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 ...
随机推荐
- 关于css的一些小细节---link
<link rel="stylesheet" href=“a.css” type="text/css"> rel:当前文档与被链接文档间的关系,必须 ...
- Java 字符流实现文件读写操作(FileReader-FileWriter)
Java 字符流实现文件读写操作(FileReader-FileWriter) 备注:字符流效率高,但是没有字节流底层 字节流地址:http://pengyan5945.iteye.com/blog/ ...
- hibernate结合使用gson转换json中一点看法
转发请注明出处:http://www.cnblogs.com/shizhongtao/p/3680216.html 在前后台的交互中,经常需要把bean对象与xml或者json,这里就把自己以前遇到的 ...
- score
#include<iostream> using namespace std; class student{ public: int Input() { ;i<;i++) { cou ...
- 使用原生Sql查询实现按分类推送最新文章到首页
一般在网站的首页都会有网站最新文章的推送,而这些文章又属于不同的分类.如果某个分类的文章突然集中在一个时间段发布,那么就会造成首页上所有文章都是该分类的文章,其他的文章分类就变成不可见的了.所以,我希 ...
- zedboard 构建嵌入式linux
本文通过五部完成zedboard的嵌入式LINUX搭建,所谓磨刀不五砍材工嘛 1:系统环境搭建 要准备好交叉编译环境 见http://blog.csdn.net/xiabodan/article/de ...
- ARP协议详解
ARP协议:地址解析协议,将IP地址映射到MAC地址. ARP缓存:每个主机都有存储IP地址和MAC地址的缓冲区.每条记录最长生存时间为10分钟,如果一条记录2分钟没有使用,则会被删除.如果始终在使用 ...
- 免费GIT托管
http://www.gitcentral.com http://www.projectlocker.com http://gitfarm.appspot.com http://code.google ...
- Global::validateEmail
/***************************************************************** (C) Copyright DENTSPLY Internatio ...
- Microsoft Visual Studio Ultimate 2015 Preview使用笔记
1.内存好象存在泄露问题