zoukankan      html  css  js  c++  java
  • bzoj1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店

    Description

    Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are: 1 @ US$3 + 1 @ US$2 1 @ US$3 + 2 @ US$1 1 @ US$2 + 3 @ US$1 2 @ US$2 + 1 @ US$1 5 @ US$1 Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).

        约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,…,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢?

    Input

    A single line with two space-separated integers: N and K.

        仅一行,输入N,K.

    Output

    A single line with a single integer that is the number of unique ways FJ can spend his money.

        不同的购买组合数.

    Sample Input

    5 3

    Sample Output

    5
     

    普通的完全背包,但是要加高精
    似乎只会写重载了(大雾)
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 int max(int &a,int &b){return a>b?a:b;}
     6 int n,k;
     7 struct bignum{
     8     int a[100],len;
     9     bignum(){memset(a,0,sizeof(a));len=0;}
    10     void print(){
    11         for(int i=len;i;--i) printf("%d",a[i]);
    12     }
    13     bignum operator + (const bignum &tmp) const{
    14         bignum c; int x=0;
    15         c.len=max(len,tmp.len);
    16         for(int i=1;i<=c.len;++i){
    17             c.a[i]=a[i]+tmp.a[i]+x;
    18             x=c.a[i]/10; c.a[i]%=10;
    19         }for(;x;x/=10) c.a[++c.len]=x%10;
    20         return c;
    21     }
    22 }f[1002];
    23 int main(){
    24     scanf("%d%d",&n,&k);
    25     f[0].a[f[0].len=1]=1;
    26     for(int i=1;i<=k;++i)
    27         for(int j=i;j<=n;++j)
    28             f[j]=f[j]+f[j-i];
    29     f[n].print();
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    Servlet学习总结
    Tomcat学习总结1
    第44周星期日反思
    第44周星期一Tomcat学习2
    第44周星期五忙碌文档的一天
    第44周星期六好文章摘录
    laravel 5.6接入微信第三方授权登陆的主要步骤
    laravel多表登录出现路由调用错误
    cURL error 60: SSL certificate problem...
    传说中Python最难理解的点|看这完篇就够了(装饰器)
  • 原文地址:https://www.cnblogs.com/kafuuchino/p/10043752.html
Copyright © 2011-2022 走看看