POJ-2226
2016-07-19 16:58
183 查看
P - Coins
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%lld
& %llu
Submit Status
Description
People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some coins.He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change)
and he known the price would not more than m.But he didn't know the exact price of the watch.
You are to write a program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of value A1,A2,A3...An then calculate how many prices(form 1 to m) Tony can pay use these coins.
Input
The input contains several test cases. The first line of each test case contains two integers n(1<=n<=100),m(m<=100000).The second line contains 2n integers, denoting A1,A2,A3...An,C1,C2,C3...Cn (1<=Ai<=100000,1<=Ci<=1000). The last test case is followed by
two zeros.
Output
For each test case output the answer on a single line.
Sample Input
Sample Output
典型的空间换时间问题。
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%lld
& %llu
Submit Status
Description
People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some coins.He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change)
and he known the price would not more than m.But he didn't know the exact price of the watch.
You are to write a program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of value A1,A2,A3...An then calculate how many prices(form 1 to m) Tony can pay use these coins.
Input
The input contains several test cases. The first line of each test case contains two integers n(1<=n<=100),m(m<=100000).The second line contains 2n integers, denoting A1,A2,A3...An,C1,C2,C3...Cn (1<=Ai<=100000,1<=Ci<=1000). The last test case is followed by
two zeros.
Output
For each test case output the answer on a single line.
Sample Input
3 10 1 2 4 2 1 1 2 5 1 4 2 1 0 0
Sample Output
8 4
典型的空间换时间问题。
#include<stdio.h> int n,i; long long num[1000005]={0}; int main() { num[1]=1; num[2]=2; for(i=3;i<=1000005;i++) { if(i%2) num[i]=num[i-1]; else num[i]=num[i-1]+num[i/2]; if(num[i]>1000000000) num[i]-=1000000000; } scanf("%d",&n); printf("%d\n",num ); }
相关文章推荐
- SlidingMenu的使用
- symbol(s) not found for architecture x86_64
- 自定义UISearchBar外观
- 设置居中
- The 101 Most Useful Websites
- 通过hive访问hbase中的表
- 【BZOJ1503】[NOI2004]郁闷的出纳员
- Spring初学者,快速理解Spring中的专业术语
- phpstorm快捷键
- k8s解决Http delete rc的时候未删除pod的问题
- 如何交办一项工作?交办和授权注意哪些事项?
- mark
- gem5、McPAT和HotSpot的联合仿真实验教程
- 构造方法
- Calendar.set方法设定日和add方法设偏离值
- linux日志回滚
- CDH的几个包的下载地址
- One Class SVM, SVDD(Support Vector Domain Description)(转)
- python os.path模块
- 在你的 composer.json 中增加 doctrine/dbal 依赖