UVa1213 - Sum of Different Primes(素数表+DP)
来源:互联网 发布:淘宝新开店铺搜索软件 编辑:程序博客网 时间:2024/05/22 11:38
题意是选择k个质数使其和为n,先搞一个素数表然后dp,dp[i][j]表示选了j个数和位i的方案数。
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn = 1120;bool check[maxn];int prime[1120];ll dp[1122][15];int init(int n){ memset(check,0,sizeof(check)); int tot=0; check[0]=check[1]=1; for(int i=2;i<=n;i++){ if(!check[i]) prime[tot++]=i; for(int j=0;j<tot;++j){ if((ll) i*prime[j]>n) break; check[i*prime[j]]=true; if(i%prime[j]==0) break; } } return tot;}int main(){ int n,k; int tot=init(maxn-1); while(~scanf("%d%d",&n,&k)&&n){ memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i=0;prime[i]<=n&&i<tot;i++) { int limt=min(i+1,k); int w=prime[i]; for(int V=n;V>=w;V--) for(int j=1;j<=limt;j++) if(dp[V-w][j-1]){ dp[V][j]+=dp[V-w][j-1]; } } cout<<dp[n][k]<<endl; } return 0;}
0 0
- UVA1213 Sum of Different Primes(素数打表+dp)
- UVa1213 - Sum of Different Primes(素数表+DP)
- UVa1213 Sum of Different Primes
- Sum of Different Primes——素数表+dp
- 习题10-5 UVA - 1213 Sum of Different Primes 不同的素数之和(DP + 素数打表)
- DP Sum of Different Primes POJ 3132
- 1213 - Sum of Different Primes(DP)
- uva 1213 Sum of Different Primes, dp
- Sum of Different Primes
- POJ 3132 & ZOJ 2822 Sum of Different Primes(dp)
- poj3132 Sum of Different Primes
- poj3132 Sum of Different Primes
- Sum of Different Primes UVA
- WOJ1274-Sum of Different Primes
- Sum of Different Primes UVA
- POJ 3132 / ZOJ 2822 : Sum of Different Primes - 动态规划,01背包,素数筛
- POJ 3132 Sum of Different Primes
- Poj 3132 Sum of Different Primes
- jmeter实践---web压力测试
- uml类图
- 腾讯视频统一调用代码
- 如何解析ajax传过来的JSON格式的字符串
- linux常用系统监控命令
- UVa1213 - Sum of Different Primes(素数表+DP)
- UML类图与类之间的关系
- 你也可以这样屌到爆的敲代码当黑客
- opencv实现camera模组的暗电流和lenshading补偿
- 播放路由宝储存卡中的dat文件的方法
- Android 设备节点查询及设备信息读取
- java 指定打印机 进行打印
- 线程与进程
- EXT.NET 后台取GridPanel全部行