# BZOJ1025 [SCOI2009]游戏 【置换群 + 背包dp】

BZOJ1025

## 题解

$$\sum\limits_{i = 1} p_i^{k_i} \le n$$，那么$$x$$显然是可以被凑出来的

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
using namespace std;
const int maxn = 1005,maxm = 100005,INF = 1000000000;
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
LL f[maxn],ans;
int n,p[maxn],pi,isn[maxn];
void init(){
for (int i = 2; i <= n; i++){
if (!isn[i]) p[++pi] = i;
for (int j = 1; j <= pi && i * p[j] <= n; j++){
isn[i * p[j]] = true;
if (i % p[j] == 0) break;
}
}
}
int main(){
init();
f[0] = 1;
for (int i = 1; i <= pi; i++){
for (int j = n; j >= 0; j--){
for (int k = p[i]; k <= j; k *= p[i])
f[j] += f[j - k];
}
}
for (int i = 0; i <= n; i++) ans += f[i];
printf("%lld\n",ans);
return 0;
}


posted @ 2018-05-11 20:50  Mychael  阅读(127)  评论(0编辑  收藏  举报