zoukankan      html  css  js  c++  java
  • BZOJ 1708: [Usaco2007 Oct]Money奶牛的硬币( dp )

    背包dp..

    --------------------------------------------------------------------------------

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<iostream>
     
    #define rep( i , n ) for( int i = 0 ; i < n ; ++i )
    #define clr( x , c ) memset( x , c ,sizeof( x ) )
     
    using namespace std;
     
    typedef long long ll;
     
    const int maxn = 10000 + 5;
     
    ll dp[ maxn ];
     
    int main() {
    int n , v;
    cin >> n >> v;
    clr( dp , 0 );
    dp[ 0 ] = 1;
    while( n-- ) {
    int w;
    scanf( "%d" , &w );
    for( int i = w ; i <= v ; i++ )
       dp[ i ] += dp[ i - w ];
    }
    cout << dp[ v ] << " ";
    return 0;
    }

      

    -------------------------------------------------------------------------------- 

    1708: [Usaco2007 Oct]Money奶牛的硬币

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 564  Solved: 368
    [Submit][Status][Discuss]

    Description

    在创立了她们自己的政权之后,奶牛们决定推广新的货币系统。在强烈的叛逆心理的驱使下,她们准备使用奇怪的面值。在传统的货币系统中,硬币的面值通常是1,5,10,20或25,50,以及100单位的货币,有时为了更方便地交易,会发行面值为2单位的硬币。 奶牛们想知道,对于一个给定的货币系统,如果需要正好凑出一定数量的钱,会有多少种不同的方法。比如说,你手上有无限多个面值为{1,2,5,10,...}的硬币,并且打算凑出18单位货币,那么你有多种方法来达到你的目的:18*1,9*2,8*2+2*1,3*5+2+1,以及其他的未列出的若干方案。 请你写一个程序,帮奶牛们计算一下,如果想用有V (1 <= V <= 25)种面值的硬币,凑出总价值为N(1 <= N <= 10,000)的一堆钱,一共有多少种不同的方法。答案保证不会超出C/C++中的'long long',Pascal中的'Int64',或是Java中的'long'的范围。

    Input

    * 第1行: 2个用空格隔开的整数:V和N

    * 第2..V+1行: 每行1个整数,表示1种硬币面值

    Output

    * 第1行: 输出1个正整数,表示用这V种面值的硬币,凑出N单位的货币的不同方法总数。

    Sample Input

    3 10
    1
    2
    5

    Sample Output

    10

    HINT

    Source

  • 相关阅读:
    leetcode 350. Intersection of Two Arrays II
    leetcode 278. First Bad Version
    leetcode 34. Find First and Last Position of Element in Sorted Array
    leetcode 54. Spiral Matrix
    leetcode 59. Spiral Matrix II
    leetcode 44. Wildcard Matching
    leetcode 10. Regular Expression Matching(正则表达式匹配)
    leetcode 174. Dungeon Game (地下城游戏)
    leetcode 36. Valid Sudoku
    Angular Elements
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4551513.html
Copyright © 2011-2022 走看看