-
Notifications
You must be signed in to change notification settings - Fork 195
/
Copy pathinteger_partition_OR_Coin_change_problem.c
86 lines (65 loc) · 1.38 KB
/
integer_partition_OR_Coin_change_problem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,n,i,j,choice, coin , amount;
int arr[100][100];
printf("Enter the operation number to be performed :- \n 1. Integer Partition \n 2. Coin Change Problem\n");
scanf("%d",&choice);
if (choice == 1)
{
printf("\nEnter the Integer :- ");
scanf("%d",&n);
a = n;
b = n;
}
else if(choice == 2)
{
printf("\nEnter the highest coin value...");
scanf("%d",&coin);
printf("\nEnter the total amount...");
scanf("%d",&amount);
a = coin;
b = amount;
}
for(i=0;i<=a;i++)
{
for (j=0;j<=b;j++)
{
arr[i][j] = 0;
}
}
for (i=1;i<=a;i++)
{
arr[i][1] = 1;
}
for (j=1;j<=b;j++)
{
arr[1][j] = 1;
}
for (i=2;i<=a;i++)
{
for (j=2;j<=b;j++)
{
arr[i][j] = arr[i-1][j] + arr[i][j-i];
}
}
printf("\n\n The number of ways = %d",arr[a][b]);
printf("\n\n Dynamic Programming Matrix......\n");
printf("\t");
for (j=0;j<=b;j++)
{
printf("%d\t",j);
}
for (i=0;i<=a;i++)
{
printf("\n");
printf("%d\t",i);
for (j=0;j<=b;j++)
{
printf("%d\t",arr[i][j]);
}
}
getchar();
return 0;
}