1. ///给你n 求他能分解成多少个的不同的k个素数相加之和
  2. ///01背包,素数打表
  3. # include <stdio.h>
  4. # include <algorithm>
  5. # include <string.h>
  6. # include <math.h>
  7. # include <iostream>
  8. using namespace std;
  9. int cot;
  10. int used[1500];
  11. int prime[1500];
  12. void sushu()///素数打表
  13. {
  14. memset(used,0,sizeof(used));
  15. cot=0;
  16. for(int i=2; i<=1120; i++)
  17. {
  18. if(!used[i])
  19. {
  20. prime[cot++]=i;
  21. for(int j=2*i; j<=1120; j+=i)
  22. used[j]=1;
  23. }
  24. }
  25. }
  26. int main()
  27. {
  28. int n,k,i,j,p;
  29. int dp[1500][20];
  30. while(~scanf("%d %d",&n,&k),n+k)
  31. {
  32. sushu();
  33. memset(dp,0,sizeof(dp));
  34. ///01背包
  35. dp[0][0]=1;
  36. for(i=0;i<cot;i++)
  37. {
  38. for(j=k;j>=1;j--)
  39. {
  40. for(p=n;p>=prime[i];p--)
  41. dp[p][j]+=dp[p-prime[i]][j-1];
  42. }
  43. }
  44. printf("%d\n",dp[n][k]);
  45. }
  46. return 0;
  47. }

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. c#实现Javascript的encodeURIComponent()函数

    原文  c#实现Javascript的encodeURIComponent()函数 国内外各搜索引擎,均用JavaScript的encodeURIComponent()函数对搜索关键字进行编码,终于找 ...

  2. truncate 和 delete 差异

    truncate table players; 相当于 delete from players;要么 delete players from players;  要么 delete players.* ...

  3. 体验魅力Cognos BI 10 系列,第1 部分: 第一次安装

    体验魅力Cognos BI 10 系列,第1 部分: 第一次安装吴敏达, 信息管理软件高级技术顾问, IBM简介: 本系列教程旨在帮助您通过实际动手掌握Cognos BI 10.1 的主要功能.在这一 ...

  4. ASM - 条件判断

    技术交流,DH讲解. 正式之前,我们看看寄存器和CPU的标志位: OD中的截图,下方的CPAZSTDO就是标志位. Delphi的FPU窗口,右边一列就是标志位.为什么要给大家看标志位呢?因为ASM中 ...

  5. Fedora 17 下安装codeblocks

    Fedora 17 下安装codeblocks:        1.直接从yum源安装:        sudo yum install codeblocks        2.源码安装        ...

  6. linux下C/C++IDE比较——Code::Blocks

    工欲善其事,必先利其器.用了这么久的linux,现在比较主流的几个C/C++的IDE基本已都用过了,现在来对他们做一下简单的比较. 1.VIM首先要说的是VIM.我认为,VIM只是一个编辑器,不能算是 ...

  7. Javascript/Jquery——简单定时器

    第一种方法: <%@ page language="java" contentType="text/html; charset=UTF-8"pageEnc ...

  8. 慎得慌二u赫然共和任务i个屁

    http://www.huihui.cn/share/8424421 http://www.huihui.cn/share/8424375 http://www.huihui.cn/share/842 ...

  9. hdu 4706

    注意一点 空的地方打空格而不是空字符,我因为这wa了一次... #include<cstdio> #include<cstring> #include<cstdlib&g ...

  10. Swift - 给表格添加Cell的显示动画(3D缩放)

    下面的一个样例是让tableView显示数据的时候具有一个很炫的3D缩放效果. 我们只需要实现tableView的willDisplayCell方法.看方法名就知道这是在Cell将要显示的时候执行的方 ...