Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
- #define ll long long
- #define ld long double
- #define pb push_back
- #define fe first
- #define se second
- #define st(x) sort(x.begin(),x.end())
- #define rst(x) sort(x.rbegin(), x.rend())
- #define all(x) x.begin(),x.end()
- long double pi = 3.14159265358979323;
- const double EPS = 1e-12;
- const int N = 1e6 + 5;
- const int mod = 998244353;
- int main()
- {
- fast;
- ll n ,val ;
- cin >> n >> val;
- ll a[n+1] = {0};
- ll sum = 0 ;
- for(int i = 1 ; i <= n ; i++ )
- {
- cin >> a[i];
- sum += a[i];
- }
- ll dp[n+1][sum+1];
- for(int i = 0 ; i <= n ; i++)
- {
- for(int j = 0 ; j <= sum ; j++ )
- {
- if(i == 0)
- dp[i][j] = 0 ;
- else if(j == 0)
- dp[i][j] = 1;
- else if(a[i] == j)
- dp[i][j] = 1;
- else if(a[i] > j)
- dp[i][j] = dp[i-1][j];
- else
- dp[i][j] = dp[i-1][j-a[i]];
- }
- }
- cout << dp[n][val] << " ";
- return 0;
- }
Add Comment
Please, Sign In to add comment