///给你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;
}

zoj 2822 Sum of Different Primes (01背包)的更多相关文章

  1. POJ 3132 &amp; ZOJ 2822 Sum of Different Primes(dp)

    题目链接: POJ:id=3132">http://poj.org/problem?id=3132 ZOJ:http://acm.zju.edu.cn/onlinejudge/show ...

  2. ZOJ - 3956 Course Selection System 【01背包变形】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意 给出N组Hi Ci 然后 要选出若干个 使得 这个式 ...

  3. ZOJ 3703 Happy Programming Contest(0-1背包)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3703 Happy Programming Contest Time Lim ...

  4. uva 624 CD (01背包)

      CD  You have a long drive by car ahead. You have a tape recorder, but unfortunately your best musi ...

  5. [UVa1213]Sum of Different Primes(递推,01背包)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  6. 2018.08.10 atcoder Median Sum(01背包)

    传送门 题意简述:输入一个数组an" role="presentation" style="position: relative;">anan. ...

  7. Codeforces Round #319 (Div. 2) B. Modulo Sum 抽屉原理+01背包

    B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  8. ZOJ 3956 Course Selection System [01背包]

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 题意:就是给你Hi,Ci的值,问怎么取使得下面那个式子的值最大: 理 ...

  9. Course Selection System ZOJ - 3956 01背包+思维

    Course Selection System ZOJ - 3956 这个题目居然是一个01背包,我觉得好难想啊,根本就没有想到. 这个题目把题目给的转化为  ans = a*a-a*b-b*b 这个 ...

随机推荐

  1. SLF4J warning or error messages and their meanings(转)

    The method o.a.commons.logging.impl.SLF4FLogFactory#release was invoked. Given the structure of the ...

  2. iOS &quot;The sandbox is not in sync with the Podfile.lock&quot;解决方式

    更新Cocoapod之后出现故障: diff: /../Podfile.lock: No such file or directory diff: Manifest.lock: No such fil ...

  3. ZOJ 3723 (浙大月赛)状压DP

    A了一整天~~~终于搞掉了. 真是血都A出来了. 题目意思很清楚,肯定是状压DP. 我们可以联系一下POJ 1185  炮兵阵地,经典的状压DP. 两道题的区别就在于,这道题的攻击是可以被X挡住的,而 ...

  4. C语言,realloc

    void * realloc ( void * ptr, size_t new_size ); 关于realloc的行为方式,结合源码总结为:1. realloc失败的时候,返回NULL: 2. re ...

  5. PHP学习之-1.5 字符串

    字符串 一个字符串是用双引号扩起来的一个词或者一个句子,比如 "Hello Word" ,你可以使用PHP语言输入这个字符串,像这样 <?php echo "Hel ...

  6. 由href return false 来看阻止默认事件

    很多时候我们都想阻止一个a ?link的href跳转. 1 <a onclick=” return false ;” href=”www. 360 .cn”>click</a> ...

  7. 【zigbee】开启及清除NV_RESTORE信息的方法

    1.NV_RESTORE宏的作用 问:coo和终端都已经组网成功 1.这时将coo断电,又一次上电,组网后终端的短地址是否不变? 2.这时终端断电,又一次上电,组网后终端的短地址是否不变? 3.这时C ...

  8. Indy10.2.5的危险做法

    为了排查一个Bug今天无意看了看Indy源码,结果吓了一跳.TIdIOHandler.ReadLongWord函数用于读取通讯数据并转换成LongWord类型返回,它做用了一种危险的做法可能会导致数据 ...

  9. 如何将excel文件中的数百万条数据在1分钟内导入数据库?

    在MYSQL里面,使用load data infile 命令就可以了. 步骤很简单 1.先将excel另存为csv格式的文本,csv是以逗号分隔各个字段数据的 2.在mysql中输入sql语句 loa ...

  10. Html网页表格结构化标记的应用

    在讲网页表格的结构化标记之前,还是先看几幅图片. Html表格的结构化 所谓的结构化,正如上述第一副图所看到的,就是把我们的表格划分为三种:表头.表体.表尾.从而当我们在改动表体部分的时候,不会影响到 ...