码迷,mamicode.com
首页 > 其他好文 > 详细

[Usaco2006 Jan] Dollar Dayz 奶牛商店

时间:2018-02-04 19:42:00      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:scan   sig   gnu   with   set   utc   names   i+1   amp   

Description

约翰到奶牛商场里买工具.商场里有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

一个简单的dp,不过要写高精度

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for (;ch<‘0‘||ch>‘9‘;ch=getchar())  if (ch==‘-‘)    f=-1;
    for (;ch>=‘0‘&&ch<=‘9‘;ch=getchar())   x=(x<<3)+(x<<1)+ch-‘0‘;
    return x*f;
}
inline void print(int x){
    if (x>=10) print(x/10);
    putchar(x%10+‘0‘);
}
const int N=1e4;
const int base=1e6;
const int digit=6;
const int maxn=1e2;
char s[maxn*digit];
struct Bignum{
    int len,v[maxn];
    void read(){
        scanf("%s",s);
        memset(v,0,sizeof(v));
        int n=strlen(s),tim=1;
        len=(n-1)/digit+1;
        for (int i=0,j=n-1;i<j;i++,j--)  swap(s[i],s[j]);
        for (int i=0;i<n;i++){
            v[i/digit]+=(s[i]-‘0‘)*tim,tim*=10;
            if (tim==base)  tim=1;
        }
    }
    void write(){
        printf("%d",v[len-1]);
        for (int i=len-2;~i;i--)    printf("%0*d",digit,v[i]);
        putchar(‘\n‘);
    }
}f[N+10];
Bignum operator +(const Bignum &x,const Bignum &y){
    Bignum z;
    memset(z.v,0,sizeof(z.v));
    z.len=max(x.len,y.len);
    for (int i=0;i<=z.len;i++)   z.v[i]+=x.v[i]+y.v[i],z.v[i+1]=z.v[i]/base,z.v[i]%=base;
    while (z.v[z.len])  z.v[z.len+1]=z.v[z.len]/base,z.v[z.len]%=base,z.len++;
    return z;
}
int main(){
    int n=read(),k=read();
    f[0].len=f[0].v[0]=1;
    for (int i=1;i<=k;i++)
        for (int j=i;j<=n;j++)
            f[j]=f[j]+f[j-i];
    f[n].write();
    return 0;
}

[Usaco2006 Jan] Dollar Dayz 奶牛商店

标签:scan   sig   gnu   with   set   utc   names   i+1   amp   

原文地址:https://www.cnblogs.com/Wolfycz/p/8413615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!