-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode nation2.c
More file actions
56 lines (47 loc) · 864 Bytes
/
code nation2.c
File metadata and controls
56 lines (47 loc) · 864 Bytes
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
#include<stdio.h>
#include<math.h>
void main()
{
int a[]={60,70,70,70};
int m=70;
int sum=0;
int i,j,c=0;
for(i=0;i<4;i++)
sum+=a[i];
int memo[5][sum+1];
memo[0][0]=1;//empty set
for(i=1;i<5;i++)
{
for(j=0;j<=sum;j++)
{
if(j>=a[i-1] )
{
if(i==1)
{
if(j==a[i-1])
memo[i][j]=1;
else
memo[i][j]=0;
if(j/i>=m && memo[i][j]==1)
c=i;
}
else
{
if(memo[i-1][j-a[i-1]]==1 || memo[i-1][j]==1)
{
memo[i][j]=1;
if(j/i>=m && memo[i][j]==1)
c=i;
}
else
memo[i][j]=0;
}
}
else
{
memo[i][j]=memo[i-1][j];
}
}
}
printf("%d",c);
}