poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 19697 | Accepted: 10800 |
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
- 2
- 3
- 17
- 41
- 20
- 666
- 12
- 53
- 0
Sample Output
- 1
- 1
- 2
- 3
- 0
- 0
- 1
- 2
- 思路:打表,不管是dp还是简单的列举首尾端点
问题:看错题意以为3 5 5 7 是允许的方式
- #include <cstdio>
- #include <cstring>
- using namespace std;
- int method[10001][1300];
- int dp[10001];
- bool isntprime[10001];
- int heap[1300],cnt;
- void calprime(){
- method[2][0]=1;
- dp[2]++;
- heap[cnt++]=2;
- for(int i=3;i<10001;i+=2){
- if(!isntprime[i]){
- heap[cnt]=i;
- method[i][cnt++]=1;dp[i]++;
- for(int j=3;i*j<10001;j+=2){
- isntprime[i*j]=true;
- }
- }
- }
- }
- void caldp(){
- for(int i=2;i<10001;i++){
- for(int j=0;j<cnt;j++){
- if(method[i][j]!=0){
- if(j<cnt-1&&i+heap[j+1]<10001){
- method[i+heap[j+1]][j+1]+=method[i][j];
- dp[i+heap[j+1]]+=method[i][j];
- }
- }
- }
- }
- }
- int main(){
- calprime();
- caldp();
- int n;
- while(scanf("%d",&n)==1&&n){
- printf("%d\n",dp[n]);
- }
- return 0;
- }
poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0的更多相关文章
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- poj 2739 Sum of Consecutive Prime Numbers 小结
Description Some positive integers can be represented by a sum of one or more consecutive prime num ...
- poj 2739 Sum of Consecutive Prime Numbers 解题报告
题目链接:http://poj.org/problem?id=2739 预处理出所有10001以内的素数,按照递增顺序存入数组prime[1...total].然后依次处理每个测试数据.采用双重循环计 ...
随机推荐
- java.lang.OutOfMemoryError: PermGen space异常及解决
PermGen space的全称是Permanent Generation space,是指内存的永久保存区域,这块内存主要是被JVM存放Class和Meta信息的,Class在被Loader时就会被 ...
- 超级强大的vim配置(vimplus)--续集
An automatic configuration program for vim 安装(github地址:https://github.com/chxuan/vimplus.git, 欢迎star ...
- qq第三方登录网站接口
网站如何实现QQ登录功能 | 浏览:11029 | 更新:2013-12-05 10:09 1 2 3 4 5 6 7 分步阅读 一键约师傅 百度师傅为你的电脑系统,选一个靠谱师傅! 如果想让网站实现 ...
- 2017年4月16日 一周AnswerOpenCV佳作赏析
2017年4月16日 一周AnswerOpenCV佳作赏析 1.HelloHow to smooth edge of text in binary image, based on threshold. ...
- openwrt的编译系统是如何制作根文件系统的
答:分析以下makefile即可获取整个过程 以nxp layerscape系统的编译过程为例 1.分析target/linux/layerscape/image/Makefile的最后一句,这是一个 ...
- rhel7配置samba_4.7.1,共享给所有人以及共享给指定用户
1.共享给所有人 服务端配置: yum -y install samba samba-client samba-common #安装客户端 mkdir /guest #创建共享文件夹 c ...
- .Net Core Cookie跨站点共享 会话保持
这里使用简单粗暴的方式,只为做个记录. 关键配置: services.AddDataProtection() .SetApplicationName("appname") .Dis ...
- 【cs231n】神经网络学习笔记3
+ mu) * v # 位置更新变了形式 对于NAG(Nesterov's Accelerated Momentum)的来源和数学公式推导,我们推荐以下的拓展阅读: Yoshua Bengio的Adv ...
- Centos中使用Jenkins执行gulp命令:command not found
在Centos操作系统,使用Jenkins的pipeline执行发布流程:jenkinsfile如下: stage("前端项目构架gulp") { steps { dir('src ...
- jmeter-负载
主: remote_hosts=10.0.70.35:1099,10.0.70.47:1099 server.rmi.localport=1099 从: remote_hosts=10.0.70.3 ...