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
  • 相关阅读:
    14.14DataSet数据集
    C#第六章学习代码
    C#第五章学习代码
    C#第四章学习代码
    C#第三章学习代码
    C#第二章学习的代码
    记录自学学习C#中写过的代码
    14._13数据集DataSet
    C#中数据库连接的几种写法
    视频、图形图像处理之Opencv技术记录(三)、相关文档页面的列表
  • 原文地址:https://www.cnblogs.com/kafuuchino/p/10043752.html
Copyright © 2011-2022 走看看