Pay the Price
来源:互联网 发布:津元天钓具淘宝 编辑:程序博客网 时间:2024/04/30 18:10
Problem F : Pay the Price
From:UVA, 10313
Submit (Out Of Contest)
In ancient days there was a country whose people had very interesting habits. Some of them were lazy, some were very rich, some were very poor and some were miser. Obviously, some of the rich were miser (A poor was never miser as he had little to spend) and lazy but the poor were lazy as well (As the poor were lazy they remained poor forever). The following things were true for that country
a) As the rich were miser, no things price was more than 300 dollars (Yes! their currency was dollar).
b) As all people were lazy, the price of everything was integer (There were no cents and so beggars always earned at least one dollar)
c) The values of the coins were from 1 to 300 dollars, so that the rich (who were idle) could pay any price with a single coin.
Your job is to find out in how many ways one could pay a certain price using a limited number of coins (Note that the number of coins paid is limited but not the value or source. I mean there was infinite number of coins of all values). For example, by using three coins one can pay six dollars in 3 ways, 1+1+4, 1+2+3, and 2+2+2. Similarly, one can pay 6 dollars using 6 coins or less in 11 ways.
Input
The input file contains several lines of input. Each line of input may contain 1, 2 or 3 integers. The first integer is always N (0<=N<=300), the dollar amount to be paid. All other integers are less than 1001 and non-negative.
Output
For each line of input you should output a single integer.
When there is only one integer N as input, you should output in how many ways N dollars can be paid.
When there are two integers N and L1 as input, then you should output in how many ways N dollars can be paid using L1 or less coins.
When there are three integers N, L1 and L2 as input, then you should output in how many ways N dollars can be paid using L1, L1+1 …, L2 coins (summing all together). Remember that L1 is not greater than L2.
Sample Input
6
6 3
6 2 5
6 1 6
Sample Output
11
7
9
11
(The Decider Contest, Problem setter: Shahriar Manzoor)
#include<iostream>#include<vector>#include<string.h>#include<sstream>using namespace std;#define maxn 310long long dp[maxn][maxn];vector<int>ve;void fact(){ dp[0][0]=1; for(int i=0;i<=300;i++){//注意0 n 的值应该是1,而不是0//dp[i][j]表示由1到j价值的钱币构成i的个数 for(int j=1;j<=300;j++){ if(i - j >= 0) dp[i][j] += dp[i - j][j]; if(j - 1 >= 0) dp[i][j] += dp[i][j - 1]; } }}int main(){ string str; int no; fact(); while(getline(cin,str)){ if(!str.length()) continue; stringstream ss(str); while(ss>>no){ ve.push_back(no); } if(ve.size()==1) cout<<dp[ve[0]][ve[0]]<<endl; else if(ve.size()==2){ if(ve[1]>=300) ve[1]=300; //solve(ve[0],ve[1]); cout<<dp[ve[0]][ve[1]]<<endl; } else{ if(ve[1]>=300) ve[1]=300; if(ve[2]>=300) ve[2]=300; // solve(ve[0],ve[2]); long long sum=dp[ve[0]][ve[2]]; if(ve[1]<=1) cout<<sum<<endl;//注意ve[1]可能为0 else{ //solve(ve[0],ve[1]-1);//注意传入参数为0的情况 long long num=dp[ve[0]][ve[1]-1]; cout<<sum-num<<endl; } } ve.clear(); } return 0;}
- 10313 - Pay the Price
- UVA10313- Pay the Price
- 10313 - Pay the Price
- Pay the Price
- uva 10313 Pay the Price
- UVA 10313 Pay the Price
- UVA 10313 Pay the Price
- uva 10313 - Pay the Price
- UVA - 10313 Pay the Price
- UVa:10313 Pay the Price
- uva 10313 - Pay the Price
- UVa 10313 - Pay the Price
- Pay the Price+uva+dp
- UVA - 10313 Pay the Price
- UVA - 10313 Pay the Price
- uva 10313 Pay the Price
- uva10313 - Pay the Price(巧妙动归)
- UVA 10313-Pay the Price(DP)
- springmvc的配置和测试
- 求有环单链表中的环长、环起点、链表长
- Unity游戏开发的数学与物理 1 ( 物体延水平方向运动 )
- 【Android进阶】Android调用WebService的实现
- Quartus II 中管脚上拉电阻(弱上拉)的设置方法
- Pay the Price
- logback
- 黑马程序员——Java基础——IO输入与输出_2
- 单链表的应用———简单的通讯录
- ‘for’ loop initial declarations are only allowed in C99 mode
- Mat, vector<point2f>,Iplimage等等常见类型转换
- 黑马程序员_____JAVA面向对象
- Effective C++读后感:以对象管理资源
- ios中的kvo模式使用实例