uva 147 Dollars(完全背包)

点击打开链接uva 147

思路: 完全背包

分析:

1 很明显裸的完全背包,注意一个地方就是输入的值不一定是小数点只有2位,这边我们应该分成两部分输入,最后注意输出即可

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int MAXN = 30010;

long long dp[MAXN];
int v[12] = {0,10000,5000,2000,1000,500,200,100,50,20,10,5};

void solve(){
    memset(dp , 0 , sizeof(0));
    dp[0] = 1;
    for(int i = 1 ; i <= 11 ; i++)
        for(int j = v[i] ; j < MAXN ; j++)
            dp[j] += dp[j-v[i]];
}

int main(){
    solve();
    int x , y;
    while(scanf("%d.%d" , &x , &y) && x+y){
        int sum = x*100+y;
        printf("%3d.%02d%17lld\n" , x , y , dp[sum]);
    }
    return 0;
}
时间: 2024-09-11 14:26:38

uva 147 Dollars(完全背包)的相关文章

UVa 147 Dollars:经典DP&amp;amp;硬币组合数&amp;amp;整数拆分

147 - Dollars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=83 和UVa 357一样. 注意所有数除以5再算. 完整代码: /*0.019s*/ #include<cstdio> #include<cstring> const int coin[11

uva 674Coin Change(完全背包)

点击打开链接uva 674 思路: 完全背包 分析: 裸题 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int MAXN = 8000; int sum , dp[MAXN]; int v[6]={0,1,5,10,25,50}; void solve(){ memset(dp , 0 , si

UVa 624 CD (0-1背包)

624 - CD Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=565 You have a long drive by car ahead. You have a tape recorder, but unfortunately your best mus

UVa 10130 SuperSale (0-1背包)

10130 - SuperSale Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1071 There is a SuperSale in a SuperHiperMarket. Every person can take only one object o

UVa 10664 Luggage (0-1背包)

10664 - Luggage Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1605 Peter and his friends are on holiday, so they have decided to make a trip by car to k

算法:uva 1407 Caves (树形背包dp)

题意 一棵n个节点的树,树的边有正整数权,表示两个节点之间的距离.你的任务是回答这样的询问:从跟 节点出发,走不超过x单位的距离, 最多能经过多少节点?同一个节点经过多次, 只能算一个. 思路 这题同样是多天前看的, 在今天才想出解法的. 动态规划就是这么有意思 :) 遍历n个节点, 有两种情 况, 第一种是遍历完之后不回到出发点, 第二种是要回到出发点. 两种都可能会重复经过某些边, 但是显 然还是第二种遍历的花费会更大 在这一题中, 遍历之后不需要回到出发点. f(i, j, 0): 表示遍

UVa 562 Dividing coins (0-1背包&amp;amp;等价转化)

562 - Dividing coins Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=503 It's commonly known that the Dutch have invented copper-wire. Two Dutch men were

uva 562 Dividing coins (0/1背包)

点击打开链接uva 562 思路: 0/1背包 分析: 1 题目意思是有两个人分n个金币,要求最后两个人的金币差值最小 2 我们利用背包的思想即背包的总容量为金币总和的一半,去求出可以放入背包的最大的金币(这里其实就是某一个人能获得的最大的金币),那么最后的ans就是(sum-dp[sum/2])-dp[sum/2] 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorit

算法题:UVA 10313(完全背包变形)

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 spe