uva 10313
递推 参考了别人的解法
dp[i][j] 表示价值为i用j个硬币可以有多少种方法
dp[j][k] += dp[j-i][k-1] 意思是多加一枚价值为i的硬币,加上价值为j-i用k-1个硬币的总数
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iostream>
#define maxn 305
#define INF 0x7fffffff
#define inf 10000000
#define ull unsigned long long
#define ll long long
using namespace std; ll dp[maxn][maxn];
char s[maxn]; void init()
{
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for(int i = 1; i < maxn; ++ i)
for(int j = i; j < maxn; ++ j)
for(int k = 1; k < maxn; ++ k)
dp[j][k] += dp[j-i][k-1];
} int main()
{
init();
int n, a, b;
while(gets(s) != NULL)
{
ll ans = 0;
int flag = sscanf(s, "%d%d%d", &n, &a, &b);
a = min(a, 300);
b = min(b, 300);
if(flag == 1)
for(int i = 0; i <= n; ++ i)
ans += dp[n][i];
else if(flag == 2)
for(int i = 0; i <= a; ++ i)
ans += dp[n][i];
else
for(int i = a; i <= b; ++ i)
ans += dp[n][i];
printf("%lld\n", ans);
}
return 0;
}
uva 10313的更多相关文章
- uva 10313 Pay the Price(完全背包)
题目连接:10313 - Pay the Price 题目大意:有0~300这300种价值的金额. 现在可能给出参数: 1个:n, 输出可以组成价值n的方式的个数. 2个:n, a输出用个数小于a的价 ...
- UVA 10313(完全背包变形)
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...
- Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) Volume 5. Dynamic Programming
10192 最长公共子序列 http://uva.onlinejudge.org/index.php?option=com_onlinejudge& Itemid=8&page=sho ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
随机推荐
- .NET中导入导出Excel总结
前一段时间,做了Excle的导入和导出,在此记录开发思路及技术要点,以便在今后开发中参考. ...
- apache commons-email1.3使用
apache commons-email1.3下载地址: https://repository.apache.org/content/repositories/orgapachecommons-0 ...
- C# 中有关 using 关键字
关于 C# 中的 using 关键字 我们往往只在代码的开头使用 using 关键字来引入名称空间,这是 using 的一个最常见的使用. 但是,using 关键字是否只有这么一处用武之地吗? 下面, ...
- 一步一步学习C++
根据<C++ primer>第五版 总结学习心得. 在实践中,不必全面地使用C++语言的各种特性,而应根据工程的实际情况,适当取舍(譬如动态类型信息,虚拟继承.异常等特性的使用,很值得商榷 ...
- 2.servlet 生命周期
1.建Web project“2Servlet_Basic” 2.建包com.amaker.servlet 3.建类“ServletBasic.java” package com.amaker.ser ...
- [C/C++]在头文件中使用static定义变量意味着什么
文章出处:http://www.cnblogs.com/zplutor/ 看到有一位同学在头文件中这么写: static const wchar_t* g_str1 = - static const ...
- cordova navigator app 对象
navigator.app.loadUrl() 加载 web 页面的应用程序中或者系统默认的浏览器中 navigator .app.cancelLoadUrl() 在 web 页面成功加载之前取消 ...
- ubuntu下安装phpstudy环境记录
下载一键安装包 下载地址:http://www.phpstudy.net/a.php/208.html 安装过程 开启终端 更改文件权限 chmod +x phpstudy 进行安装 ./phpstu ...
- [大牛翻译系列]Hadoop(4)MapReduce 连接:选择最佳连接策略
4.1.4 为你的数据选择最佳连接策略 已介绍的每个连接策略都有不同的优点和缺点.那么,怎么来判断哪个最适合待处理的数据? 图4.11给出了一个决策树.这个决策树是于论文<A Compariso ...
- HIVE中join、semi join、outer join举例详解
转自 http://www.cnblogs.com/xd502djj/archive/2013/01/18/2866662.html 举例子: hive> select * from zz0; ...