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 |
#include <iostream> #include <string> #include <sstream> #define ll long long using namespace std; ll ways[400][400]; ll findways(int a,int b) { ll r=0; if(ways[a][b]!=-1) return ways[a][b]; if(a==0) return 1; else { r = 0; for(int i=b;i>=1;i--) if(a-i>=0) { r+=findways(a-i,i); //ways[a-i][i]=r; } ways[a][b]=r; } return r; } int main() { int a[3],b,c,n; string s; stringstream ss; for(int i=0;i<400;i++) for(int j=0;j<400;j++) ways[i][j]=-1; while(getline(cin,s)) { int k=0; //getline(cin,s); ss.clear(); ss<<s; while(ss>>n) { if(n>300) n=300; a[k++]=n; } if(k==1) { cout<<findways(a[0],a[0])<<"\n"; } if(k==2) { cout<<findways(a[0],a[1])<<"\n"; } else if(k==3) { cout<<findways(a[0],a[2])-findways(a[0],a[1]-1)<<"\n"; } } return 0; } |