Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
subset sum=k(Recursion)
#include<bits/stdc++.h> using namespace std; bool check(vector<int>v,int n,int sum) { if(sum==0 && n==0) { return 1; } else if(sum!=0 && n==0) { return 0; } else if(sum==0 && n!=0) { return 1; } else if(v[n-1]>sum) { return check(v,n-1,sum); } else { return (check(v,n-1,sum) || check(v,n-1,sum-v[n-1])); } } int main() { int n; cin>>n; int sum; cin>>sum; vector<int>v; for(int i=0;i<n;i++) { int g; cin>>g; v.push_back(g); } int c=check(v,n,sum); if(c) { cout<<"Y"<<endl; } else { cout<<"N"<<endl; } }
run
|
edit
|
history
|
help
0
Segment Tree
პირამიდის ფართობი~ფინალური
printAllPathsInMatrix
temp
Przesylka
find duplicate in O(n)
Count squares
Expected types
2
half diamond or pyramid