#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
vector<vector<long long int> > dp(301,vector<long long int>(301,-1));
vector<vector<vector<long long int> > > dp2(301,vector<vector<long long int> >(1001,vector<long long int>(301,-1)));
long long int cc(int sum,int i){
if(sum==0) return 1;
if(sum<0||i>sum) return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
return dp[i][sum]=cc(sum,i+1)+cc(sum-i,i);
}
long long int cc(int sum,int i,int k){
if(sum==0)return 1;
if(sum<0||i>sum||k==0)return 0;
if(dp2[i][k][sum]!=-1)return dp2[i][k][sum];
return dp2[i][k][sum]=cc(sum,i+1,k)+cc(sum-i,i,k-1);
}
int main(){
while(true){
ws(cin);
if(cin.eof())return 0;
int n,a,b,m=0,i=0;
string s;
getline(cin,s);
// cout<<s<<endl;
while(i<s.size()){
string tmp;
while(i<s.size()&&s[i]!=' '){
tmp.push_back(s[i]);
i++;
}
i++;
stringstream ss(tmp);
if(m==0)ss>>n;
else if(m==1)ss>>a;
else ss>>b;
m++;
}
// cout<<n<<' '<<m<<endl;
if(m==1)cout<<cc(n,1)<<endl;
else if(m==2)cout<<cc(n,1,a)<<endl;
else {
if(a>0)
cout<<cc(n,1,b)-cc(n,1,a-1)<<endl;
else
cout<<cc(n,1,b)<<endl;
}
// cout<<"yo"<<endl;
}
return 0;
}
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
vector<vector<long long int> > dp(301,vector<long long int>(301,-1));
vector<vector<vector<long long int> > > dp2(301,vector<vector<long long int> >(1001,vector<long long int>(301,-1)));
long long int cc(int sum,int i){
if(sum==0) return 1;
if(sum<0||i>sum) return 0;
if(dp[i][sum]!=-1)return dp[i][sum];
return dp[i][sum]=cc(sum,i+1)+cc(sum-i,i);
}
long long int cc(int sum,int i,int k){
if(sum==0)return 1;
if(sum<0||i>sum||k==0)return 0;
if(dp2[i][k][sum]!=-1)return dp2[i][k][sum];
return dp2[i][k][sum]=cc(sum,i+1,k)+cc(sum-i,i,k-1);
}
int main(){
while(true){
ws(cin);
if(cin.eof())return 0;
int n,a,b,m=0,i=0;
string s;
getline(cin,s);
// cout<<s<<endl;
while(i<s.size()){
string tmp;
while(i<s.size()&&s[i]!=' '){
tmp.push_back(s[i]);
i++;
}
i++;
stringstream ss(tmp);
if(m==0)ss>>n;
else if(m==1)ss>>a;
else ss>>b;
m++;
}
// cout<<n<<' '<<m<<endl;
if(m==1)cout<<cc(n,1)<<endl;
else if(m==2)cout<<cc(n,1,a)<<endl;
else {
if(a>0)
cout<<cc(n,1,b)-cc(n,1,a-1)<<endl;
else
cout<<cc(n,1,b)<<endl;
}
// cout<<"yo"<<endl;
}
return 0;
}
Comments
Post a Comment