2015 程序设计实习之动规作业2
来源:互联网 发布:聚宝盆营销软件 编辑:程序博客网 时间:2024/04/29 18:44
A:UNIMODAL PALINDROMIC DECOMPOSITIONS(1221POJ)
- 查看
- 提交
- 统计
- 提问
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
A sequence of positive integers is Palindromic if it reads the same forward and backward. For example:
23 11 15 1 37 37 1 15 11 23
1 1 2 3 4 7 7 10 7 7 4 3 2 1 1
A Palindromic sequence is Unimodal Palindromic if the values do not decrease up to the middle value and then (since the sequence is palindromic) do not increase from the middle to the end For example, the first example sequence above is NOT Unimodal Palindromic while the second example is.
A Unimodal Palindromic sequence is a Unimodal Palindromic Decomposition of an integer N, if the sum of the integers in the sequence is N. For example, all of the Unimodal Palindromic Decompositions of the first few integers are given below:
1: (1)
2: (2), (1 1)
3: (3), (1 1 1)
4: (4), (1 2 1), (2 2), (1 1 1 1)
5: (5), (1 3 1), (1 1 1 1 1)
6: (6), (1 4 1), (2 2 2), (1 1 2 1 1), (3 3),
(1 2 2 1), ( 1 1 1 1 1 1)
7: (7), (1 5 1), (2 3 2), (1 1 3 1 1), (1 1 1 1 1 1 1)
8: (8), (1 6 1), (2 4 2), (1 1 4 1 1), (1 2 2 2 1),
(1 1 1 2 1 1 1), ( 4 4), (1 3 3 1), (2 2 2 2),
(1 1 2 2 1 1), (1 1 1 1 1 1 1 1)
Write a program, which computes the number of Unimodal Palindromic Decompositions of an integer.- 输入
- Input consists of a sequence of positive integers, one per line ending with a 0 (zero) indicating the end.
- 输出
- For each input value except the last, the output is a line containing the input value followed by a space, then the number of Unimodal Palindromic Decompositions of the input value. See the example on the next page.
- 样例输入
2345678102324131213920
- 样例输出
2 23 24 45 36 77 58 1110 1723 10424 199131 5010688213 105585259092 331143
- 提示
- N < 250
#include<iostream>#include<memory.h>using namespace std;long long f[250][250];//long long 据说不写longlong会WA int num;long long wf(int n,int k){ if(n==k) return f[n][n]; if(n<2*k) return 0; if(n==2*k) return 1; if(f[n-2*k][k]!=0) return f[n-2*k][k]; else { int temp=0; for(int i=k;i<=n-2*k;++i) temp+=wf(n-2*k,i); f[n-2*k][k]=temp; return f[n-2*k][k]; }}void compute(int n){ if(f[n][1]!=0) return ; else { for(int i=1;i<=n;++i) f[n][1]+=wf(n,i); } return ;}int main(){ memset(f,0,sizeof(f)); for(int i=1;i<250;++i) f[i][i]=1; while(cin>>num) { if(num==0)break; compute(num); cout<<num<<' '<<f[num][1]<<endl; } return 0; }
B:Charm Bracelet
- 查看
- 提交
- 统计
- 提问
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N(1 ≤ N≤ 3,402) available charms. Each charm iin the supplied list has a weight Wi(1 ≤ Wi≤ 400), a 'desirability' factor Di(1 ≤ Di≤ 100), and can be used at most once. Bessie can only support a charm bracelet whose weight is no more than M(1 ≤ M≤ 12,880).
Given that weight limit as a constraint and a list of the charms with their weights and desirability rating, deduce the maximum possible sum of ratings.
- 输入
- Line 1: Two space-separated integers: N and M
Lines 2..N+1: Line i+1 describes charm i with two space-separated integers: Wi and Di - 输出
- Line 1: A single integer that is the greatest sum of charm desirabilities that can be achieved given the weight constraints
- 样例输入
4 61 42 63 122 7
- 样例输出
23
- 来源
- USACO 2007 December Silver
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespace std;int N,M;int cost[3500];int desire[3500];int d[13000];//d[i][j]表示将前i件物品放入容量为j的背包的最大值int main(){ while(scanf("%d %d",&N,&M)!=EOF) { int i,j; for(i=0;i<N;i++) { scanf("%d %d",&cost[i],&desire[i]); } for(i=0;i<=M;i++) { d[i]=0; } for(i=1;i<=N;i++) { for(j=M;j>=0;j--) { if(j-cost[i-1]<0) { continue; } d[j]=d[j]>(d[j-cost[i-1]]+desire[i-1])?d[j]:(d[j-cost[i-1]]+desire[i-1]); } } printf("%d\n",d[M]); } return 0;}
- 2015 程序设计实习之动规作业2
- 2015 程序设计实习之递归+动规作业1
- 2015 程序设计实习之递归作业
- 2015 程序设计实习之深搜+广搜作业
- 北大程序设计实习MOOC 编程作业 《魔兽世界之二:装备》
- 2015程序设计实习之第二次上机周六
- 北大程序设计实习公开课编程作业,魔兽世界之二:装备
- 课后作业之动物类
- OpenJudge程序设计实习之递归
- 【北大MOOC】2014程序设计实习--第二周编程作业
- 程序设计实习MOOC/第十三周编程作业/A:集合加法
- 程序设计实习MOOC/第十三周编程作业/D:滑雪
- 程序设计实习MOOC/第十四周编程作业/B:迷宫问题
- 程序设计实习MOOC/第十五周编程作业/A:棋盘问题
- 北大程序设计实习公开课编程作业,魔兽世界之一:备战
- 程序设计实习之STL专项练习
- 现代程序设计 作业 2
- 现代程序设计 作业 2
- JQuery+Ajax 整理
- CMD:[3]获取驱动器或文件夹内的文件列表
- 2015.5.26
- iOS点击空白区域隐藏键盘
- [前端] 简单的cookie操作
- 2015 程序设计实习之动规作业2
- Cubieboard2-Android-Cubie-Screen 模组调试说明 修正1可以显示了 windows ANSI.txt
- 矩阵C++实现
- gdb 调试go
- Bower —— 管理你的客户端依赖关系
- osx使用cmake编译opencv错误记录
- MyBatis学习总结(三)——优化MyBatis配置文件中的配置
- 在UIWebView中实现缓存功能
- Oracle误删除表数据后的恢复详解