-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquestion60.c
63 lines (47 loc) · 951 Bytes
/
question60.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
/*
http://practice.geeksforgeeks.org/problems/cutted-segments/0
This is similar to coin sum problem just that max coins are to be found
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int max(int a, int b){
return a > b? a:b;
}
int cuttedSegments(int length, int x, int y, int z) {
int arr[] = {x,y,z};
int size = sizeof(arr)/sizeof(arr[0]);
int dp[size+1][length+1];
int i,j;
for(i=0;i<=size;i++){
dp[i][0] = 0;
}
for(i=0;i<=length;i++){
dp[0][i] = INT_MIN;
}
dp[0][0] = 0;
for(i=1;i<=size;i++){
for(j=1;j<=length;j++){
if(arr[i-1] <= j){
dp[i][j] = max(1+dp[i][j-arr[i-1]], dp[i-1][j]);
}else{
dp[i][j] = dp[i-1][j];
}
}
}
return dp[size][length];
}
int main(){
int cases;
scanf("%d",&cases);
int i;
for(i=0;i<cases;i++){
int n;
scanf("%d",&n);
int x,y,z;
scanf("%d %d %d",&x, &y,&z);
printf("%d\n", cuttedSegments(n,x,y,z));
}
return 0;
}