-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeep Counting.cpp
More file actions
81 lines (64 loc) · 1.28 KB
/
Keep Counting.cpp
File metadata and controls
81 lines (64 loc) · 1.28 KB
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
#include<bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
typedef long long ll;
using namespace std;
int a[105];
int cum[105];
//long long int alpha[105][55]={0};
int upperbound(int target, int n)
{
int low = 0;
int high = n;
int mid;
while(low != high)
{
mid = (low + high)/2;
if(target >= a[mid])
low = mid+1;
else
high = mid;
}
return low;
}
long long int count(int index, int target)
{
//if(alpha[index][target]!=0)
//return alpha[index][target];
if(target==0)
return 1;
else if(index < 0 || target < 0)
return 0;
else if(target > cum[index])
return 0;
long long int sum = 0;
for(int i = index; i>=0; i--)
{
//int z = count(i-1, target-a[i]);
//if(z)
//cout<<i<<" "<<target<<" "<<index<<endl;
//sum+=z;
sum += count(i-1, target-a[i]);
}
//alpha[index][target] = sum;
return sum;
}
int main()
{
int n,t;
cin>>n>>t;
for(int i = 0; i<n; ++i)
cin>>a[i];
//a[i] = 1;
cum[0] = a[0];
for(int i = 1; i<n; i++)
cum[i] = cum[i-1] + a[i];
sort(a,a+n);
int ub = upperbound(t,n);
if(ub==n)
ub--;
//cout<<ub<<endl;
cout<<count(ub,t);
return 0;
}