//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1500
#define MOD 1000000007
int n,m,a[MAX],dp[200][1200][17];
vi v;
// Bottom-up Approach
int solve(int i,int n,int k){
if(n<0 || k<0 || i>=200)
return 0;
if(n==0 && k==0){
return dp[i][n][k]=1;
}
if(dp[i][n][k]!=-1)
return dp[i][n][k];
if(v[i]>n)
return dp[i][n][k]=0;
return dp[i][n][k]=solve(i+1,n,k)+solve(i+1,n-v[i],k-1);
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
f(i,2,MAX){
if(!a[i]){
for(j=2*i;j<MAX;j+=i)
a[j]=1;
}
}
v.pb(0);
f(i,2,MAX){
if(!a[i])
v.pb(i);
}
// Top-Down Approach
dp[0][0][0]=1;
f(l,0,17){
f(j,0,1200){
f(i,1,200){
if(l==0 && j>0)
dp[i][j][l]=0;
else if(j==0 && l==0)
dp[i][j][l]=1;
else{
dp[i][j][l]=dp[i-1][j][l];
if(v[i]<=j && l>0)
dp[i][j][l]+=dp[i-1][j-v[i]][l-1];
}
}
}
}
while(1){
sii(n,k);
if(n==0 && k==0)
break;
pi(dp[199][n][k]);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1500
#define MOD 1000000007
int n,m,a[MAX],dp[200][1200][17];
vi v;
// Bottom-up Approach
int solve(int i,int n,int k){
if(n<0 || k<0 || i>=200)
return 0;
if(n==0 && k==0){
return dp[i][n][k]=1;
}
if(dp[i][n][k]!=-1)
return dp[i][n][k];
if(v[i]>n)
return dp[i][n][k]=0;
return dp[i][n][k]=solve(i+1,n,k)+solve(i+1,n-v[i],k-1);
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p;
f(i,2,MAX){
if(!a[i]){
for(j=2*i;j<MAX;j+=i)
a[j]=1;
}
}
v.pb(0);
f(i,2,MAX){
if(!a[i])
v.pb(i);
}
// Top-Down Approach
dp[0][0][0]=1;
f(l,0,17){
f(j,0,1200){
f(i,1,200){
if(l==0 && j>0)
dp[i][j][l]=0;
else if(j==0 && l==0)
dp[i][j][l]=1;
else{
dp[i][j][l]=dp[i-1][j][l];
if(v[i]<=j && l>0)
dp[i][j][l]+=dp[i-1][j-v[i]][l-1];
}
}
}
}
while(1){
sii(n,k);
if(n==0 && k==0)
break;
pi(dp[199][n][k]);
}
return 0;
}
No comments:
Post a Comment