zoj 2822 Sum of Different Primes (01背包)
来源:互联网 发布:淘宝五年老店有什么用 编辑:程序博客网 时间:2024/04/29 06:36
///给你n 求他能分解成多少个的不同的k个素数相加之和///01背包,素数打表# include <stdio.h># include <algorithm># include <string.h># include <math.h># include <iostream>using namespace std;int cot;int used[1500];int prime[1500];void sushu()///素数打表{ memset(used,0,sizeof(used)); cot=0; for(int i=2; i<=1120; i++) { if(!used[i]) { prime[cot++]=i; for(int j=2*i; j<=1120; j+=i) used[j]=1; } }}int main(){ int n,k,i,j,p; int dp[1500][20]; while(~scanf("%d %d",&n,&k),n+k) { sushu(); memset(dp,0,sizeof(dp)); ///01背包 dp[0][0]=1; for(i=0;i<cot;i++) { for(j=k;j>=1;j--) { for(p=n;p>=prime[i];p--) dp[p][j]+=dp[p-prime[i]][j-1]; } } printf("%d\n",dp[n][k]); } return 0;}
0 0
- zoj 2822 Sum of Different Primes (01背包)
- POJ 3132 / ZOJ 2822 : Sum of Different Primes - 动态规划,01背包,素数筛
- zoj 2822 - Sum of Different Primes
- POJ 3132 & ZOJ 2822 Sum of Different Primes(dp)
- 【01背包方案数】POJ-3132 Sum of Different Primes
- poj 3132 Sum of Different Primes(01背包)
- uva 1213 sum of different primes 01背包(二维)
- POJ 3132 Sum of Different Primes 【01背包】
- Sum of Different Primes
- UVa1213 Sum of Different Primes
- 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 Sum of Different Primes
- Poj 3132 Sum of Different Primes
- POJ3122 - Sum of Different Primes - 动态规划
- 异步加载图片框架Android-Universal-Image-Loader的使用
- LeetCode:《Min Stack》
- 第6章MapReduce--Hadoop作业的调度
- -----------------成长语录-----------------
- request.getPathInfo() 方法的作用
- zoj 2822 Sum of Different Primes (01背包)
- NIO新功能Top 10(上)
- 浏览器下载排行榜2015
- Java NIO服务器实例
- 划水划水——EA导出各种乱七八糟的东西
- 用VS2012或VS2013在win7下编写的程序在XP下运行就出现“不是有效的win32应用程序
- Java虚拟机——内存管理与垃圾回收
- mysql慢查询原因分析与解决(四)——配置优化
- linux-overcommit_memory