-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdp1.cpp
60 lines (49 loc) · 945 Bytes
/
dp1.cpp
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
#include<iostream>
#include<vector>
using namespace std;
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include <set>
#define ll long long int
#define ull unsigned long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mods 1000000007
knapsack(int a[],int n,int sum){
int t[n+1][sum+1];
for(int i=0;i<n+1;i++){
t[i][0]=1;
}
for(int i=1;i<sum+1;i++){
t[0][i]=0;
}
for(int i=1;i<n+1;i++){
for(int j=1;j<sum+1;j++){
if(a[i-1]<=j){
t[i][j]= (t[i-1][j - a [i-1]]) + t[i-1][j];
}
else{
t[i][j]=t[i-1][j];
}
}
}
return (t[n][sum]);
}
int main(){
int t=1;
// cin>>t;
while(t--){
int n,sum=0,s=0,diff=0;
cin>>n>>diff;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
s=s+arr[i];
}
sum=((s+diff)/2);
//cout<<sum;
sort(arr,arr+n);
int p=knapsack(arr ,n ,sum);
cout<<p<<"\n";
}
}