题目连接:10313 - Pay the Price

题目大意:有0~300这300种价值的金额。

现在可能给出参数:

1个:n, 输出可以组成价值n的方式的个数。

2个:n, a输出用个数小于a的价值组成价值n的方式的个数。

3个:n, a, b输出用个数大于a和小于b组成价值n的方式的个数。

解题思路:完全背包的问题, 状态转移方程dp[i][j] 表示价值i用j个硬币组成的方式种类, 转移方程dp[j][k] += dp[j - i][k - 1]。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int N = 305; long long dp[N][N]; void Init() {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 1; i <= 300; i++) {
for (int j = i; j <= 300; j++) {
for (int k = 1; k <= 300; k++)
dp[j][k] += dp[j - i][k - 1];
}
}
} int main() {
Init();
int n, a, b;
char str[N];
while (gets(str)) {
int flag = sscanf(str, "%d%d%d", &n, &a, &b);
long long sum = 0;
if (a > 300) a = 300;
if (b > 300) b = 300;
if (flag == 1) {
for (int i = 0; i <= n; i++)
sum += dp[n][i];
}
else if (flag == 2) {
for (int i = 0; i <= a; i++)
sum += dp[n][i];
}
else if (flag == 3) {
for (int i = a; i <= b; i++)
sum += dp[n][i];
}
printf("%lld\n", sum);
}
return 0;
}

uva 10313 Pay the Price(完全背包)的更多相关文章

  1. UVA 10313(完全背包变形)

    Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...

  2. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

  3. UVA 562 Dividing coins (01背包)

    题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum,   A,B其中必有一人获得的钱小于等于sum/2 ...

  4. UVA 10465 Homer Simpson(dp + 完全背包)

    Problem C: Homer Simpson Time Limit: 3 seconds Memory Limit: 32 MB Homer Simpson, a very smart guy, ...

  5. UVA 562 Dividing coins(dp + 01背包)

    Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were figh ...

  6. uva 10404 Bachet's Game(完全背包)

    题目连接:10404 - Bachet's Game 题目大意:由一堆石子, 给出石子的总数, 接下来由stan和ollie两个人玩游戏,给出n, 在给出n种取石子的方法(即为每次可取走石子的数量), ...

  7. UVa 674 Coin Change(完全背包)

    https://vjudge.net/problem/UVA-674 题意: 计算兑换零钱的方法共有几种. 思路: 完全背包基础题. #include<iostream> #include ...

  8. UVa 12563 劲歌金曲(0-1背包)

    https://vjudge.net/problem/UVA-12563 题意: 在一定的时间内连续唱歌,最后一首唱11分钟18秒的劲歌金曲,问最多能长多长时间. 思路: 0-1背包问题,背包容量为t ...

  9. UVA 562 Dividing coins【01背包 / 有一堆各种面值的硬币,将所有硬币分成两堆,使得两堆的总值之差尽可能小】

    It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nic ...

随机推荐

  1. Oracle存储包存储及案例

    Package左侧文件: create or replace package S02_ZFRZPT_YS_MID is procedure start_cal(strgranularity in va ...

  2. 五毛的cocos2d-x学习笔记01-创建项目

    终于准备开始学习cocos2d-x了.因为想和同学一起做游戏参加比赛,所以打算学习很热的Cocos2d-x.因为已经学习了C++,所以我想入门应该不是很困难.再加上官网有中文教程以及多不胜数的游戏开发 ...

  3. Codeforces Round #316 (Div. 2C) 570C Replacement

    题目:Click here 题意:看一下题目下面的Note就会明白的. 分析:一开始想的麻烦了,用了树状数组(第一次用)优化,可惜没用. 直接判断: #include <bits/stdc++. ...

  4. Vmware中Ubuntu挂ISO到虚拟光驱

    Ubuntu 下挂ISO到虚拟光驱的方法 https://i.cnblogs.com/EditPosts.aspx?opt=1 如果要ubuntu找到rpm软件包,需要把iso挂载到/media/cd ...

  5. 【Linux命令】杀死僵尸程序

    A zombie is already dead, so you cannot kill it. To clean up a zombie, it must be waited on by its p ...

  6. UIWebvView 解决onClick 延迟相应问题

    在使用 UIWebView 的过程中, 发现 onClick 触发需要等待300-500ms, Google了一下, 发现是因为ScrollView 在等待doubleTap, 所以有延迟 使用如下代 ...

  7. windos下安装PEAR 注意

    1.在这里下载PEAR http://pear.php.net/go-pear.phar 在页面右键另存为 go-pear.phar 到PHP的根目录,并去目录查看是否保存为了go-pear.phar ...

  8. poj 1850/poj 1496

    http://poj.org/problem?id=1850 -----------------http://poj.org/problem?id=1496 两题解法类似..本题为组合数学的题,要求所 ...

  9. Fedora最小化安装后没有ifconfig命令

    百度了很久,都说添加export PATH=$PATH:/sbin,结果我用whereis 查询了,根本没有这个命令.后来直接yum search ifconfig,查找到原来是net-tools包. ...

  10. setuptools,easy_install使用

    当需要安装第三方python包时,可能会用到easy_install命令.easy_install是由PEAK(Python Enterprise Application Kit)开发的setupto ...