Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize ("O3")
- #pragma GCC target ("sse4")
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<string,int> psi;
- typedef priority_queue<int> pqmax;
- typedef priority_queue<int,vector<int>,greater<int>> pqmin;
- typedef unordered_map<int,int> mii;
- typedef unordered_map<long long,long long> mll;
- typedef unordered_map<string,int> msi;
- typedef unordered_map<char,int> mci;
- typedef unordered_set<int> si;
- typedef unordered_set<long long> sll;
- typedef unordered_set<string> ss;
- typedef unordered_set<char> sc;
- typedef map<int,int> ormii;
- typedef map<long long,long long> ormll;
- typedef map<string,int> ormsi;
- typedef map<char,int> ormci;
- typedef set<int> orsi;
- typedef set<long long> orsll;
- typedef set<string> orss;
- typedef set<char> orsc;
- typedef vector<int> vi;
- typedef vector<string> vs;
- typedef vector<char> vc;
- typedef vector<ll> vll;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<string>> vvs;
- typedef vector<vector<bool>> vvb;
- typedef vector<vector<ll>> vvll;
- #define FOR(i, a, b) for (auto i=a; i<=(b); i++)
- #define FORd(i,b,a) for (int i =b; i >= a; i--)
- #define sortinc(v) sort(v.begin(),v.end())
- #define sortdec(v) sort(v.rbegin(),v.rend())
- #define sz(x) (int)(x).size()
- #define mp make_pair
- #define pb push_back
- #define pob pop_back
- #define pf push_front
- #define pof pop_front
- #define fi first
- #define se second
- #define ins insert
- const int MOD = 1000000007;
- int m(ll k) {return k%MOD;}
- //type functions here
- int solve(vector<int> &A, int B) {
- int n=A.size();
- vvi dp(n+1,vector<int>(B+1,0));
- for(int i=0;i<=B;i++) dp[0][i]=0;
- for(int i=0;i<=n;i++) dp[i][0]=1;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=B;j++)
- {
- if(j>=A[i-1])//current element is not exceeded the sum to acheieve
- dp[i][j]=(dp[i-1][j])+(dp[i-1][j-A[i-1]]);
- else//if exceeded we have to solely depend on n-1 element current sum
- dp[i][j]=dp[i-1][j];
- }
- }
- return dp[n][B];
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tc=1;
- //cin>>tc;
- FOR(w,1,tc)
- {
- vi A={1,2,3,1};
- int B=2;
- cout<<solve(A,B)<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement