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 奶牛商店的更多相关文章

  1. bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店

    Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of to ...

  2. 【BZOJ】1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(背包+高精度)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1655 背包就没什么好说的了,裸的完全背包.. 但是我一开始交开了ull都wa了T_T.. 精度太大. ...

  3. bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店【高精度+完全背包】

    居然要用高精度! 懒得operator了,转移是裸的完全背包 #include<iostream> #include<cstdio> using namespace std; ...

  4. 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法

    [BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...

  5. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  6. BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )

    tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...

  7. [Usaco2006 Jan] Redundant Paths 分离的路径

    1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1132  Solv ...

  8. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  9. BZOJ1612: [Usaco2008 Jan]Cow Contest奶牛的比赛

    1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 645  Solved: 433 ...

随机推荐

  1. zz年度热门编程语言排行榜

    原文在这里:Link 蛮有意思的,可以看看.

  2. [Rust] Setup Rust for WebAssembly

    In order to setup a project we need to install the nightly build of Rust and add the WebAssembly tar ...

  3. POJ 1436 Horizontally Visible Segments(线段树)

    POJ 1436 Horizontally Visible Segments 题目链接 线段树处理染色问题,把线段排序.从左往右扫描处理出每一个线段能看到的右边的线段,然后利用bitset维护枚举两个 ...

  4. Office EXCEL 的绝对引用和相对引用如何理解

    比如C1 = A1+B1,则我把C1的单元格往下拖拉的时候,C2会自动等于A2+B2,C3会自动等于A3+B3,而如果让G1 = $E$1+$F$1,则把G1单元格往下拖拉的时候,G2G3单元格都不会 ...

  5. MongoDB中对象反序列化的一个小问题

    今天在mongoDB存取对象数据的时候,碰到一个小问题:对象的某一个字段类型是抽象类或者接口.在存入的时候没有问题.可是在读取的时候,因为没有详细类的信息,无法完毕对象的又一次构建.就会报错: Can ...

  6. Linux - Ubuntu中文输入法安装(Ubuntu 12.04)

    Ubuntu中文输入法安装(Ubuntu 12.04) 本文地址:http://blog.csdn.net/caroline_wendy Ubuntu作为Linux常见的操作系统,是须要熟练使用的. ...

  7. Web安全漏洞及攻击

    背景介绍 先说一个在互联网上常见,但是普通人又不太理解的东西--“验证码”. 验证码(CAPTCHA)是“Completely Automated Public Turing test to tell ...

  8. iOS 获取手机 唯一标识

    存贮在keychainQuery 可以统计用户使用情况 -(void)gatherMessage{ //采集用户设备信息 NSUserDefaults *userDefaults=[NSUserDef ...

  9. android 浮动窗体学习笔记及个人理解(仿360手机助手)

    很感谢原文作者 http://blog.csdn.net/guolin_blog/article/details/8689140 经自己理解 程序执行界面例如以下图: 1.程序入口界面 2.小浮动窗体 ...

  10. TestNg的工厂測试引用@DataProvider数据源----灵活使用工厂測试

    之前说过@Factory更适合于同一类型的參数变化性的測试,那么假设參数值没有特定的规律时,我们能够採用@Factory和@DataProvider相结合的方式进行測试 注意要点:请注意測试方法将被一 ...