Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from begeekmyfriend:master #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 1 commit into AlgorithmAndLeetCode:master from begeekmyfriend:master
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add new case
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
  • Loading branch information
begeekmyfriend committed Jun 10, 2025
commit 999ff027352c37a14de2c07c4158ccd6b31a926b
2 changes: 2 additions & 0 deletions 0518_coin_change_ii/Makefile
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
gcc -O1 -o test coin_change.c
44 changes: 44 additions & 0 deletions 0518_coin_change_ii/coin_change.c
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>


int change(int amount, int* coins, int coinsSize)
{
int i, j;
unsigned int **dp = malloc((coinsSize + 1) * sizeof(unsigned int *));

for (i = 0; i <= coinsSize; i++) {
dp[i] = calloc(amount + 1, sizeof(unsigned int));
dp[i][0] = 1;
}

for (i = 1; i <= coinsSize; i++) {
for (j = 1; j <= amount; j++) {
if (j - coins[i - 1] >= 0) {
dp[i][j] = dp[i - 1][j] + dp[i][j - coins[i - 1]];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}

return dp[coinsSize][amount];
}

int main(int argc, char **argv)
{
if (argc < 3) {
fprintf(stderr, "Usage: ./test 11 1 2 5");
exit(-1);
}

int amount = atoi(argv[1]);
int i, size = argc - 2;
int *coins = malloc(size * sizeof(int));
for (i = 0; i < size; i++) {
coins[i] = atoi(argv[i + 2]);
}
printf("%d\n", change(amount, coins, size));

return 0;
}
24 changes: 24 additions & 0 deletions 0518_coin_change_ii/coin_change.cc
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
int change(int amount, vector<int>& coins) {
vector<vector<unsigned int>> dp(coins.size() + 1, vector<unsigned int>(amount + 1));
for (int i = 0; i <= coins.size(); i++) {
dp[i][0] = 1;
}

for (int i = 1; i <= coins.size(); i++) {
for (int j = 1; j <= amount; j++) {
if (j >= coins[i - 1]) {
dp[i][j] = dp[i - 1][j] + dp[i][j - coins[i - 1]];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[coins.size()][amount];
}
};

AltStyle によって変換されたページ (->オリジナル) /