[Usaco2006 Jan] Dollar Dayz 奶牛商店
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 奶牛商店的更多相关文章
- bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店
Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of to ...
- 【BZOJ】1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(背包+高精度)
http://www.lydsy.com/JudgeOnline/problem.php?id=1655 背包就没什么好说的了,裸的完全背包.. 但是我一开始交开了ull都wa了T_T.. 精度太大. ...
- bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店【高精度+完全背包】
居然要用高精度! 懒得operator了,转移是裸的完全背包 #include<iostream> #include<cstdio> using namespace std; ...
- 【BZOJ1720】[Usaco2006 Jan]Corral the Cows 奶牛围栏 双指针法
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for h ...
- 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 & ...
- BZOJ 1718: [Usaco2006 Jan] Redundant Paths 分离的路径( tarjan )
tarjan求边双连通分量, 然后就是一棵树了, 可以各种乱搞... ----------------------------------------------------------------- ...
- [Usaco2006 Jan] Redundant Paths 分离的路径
1718: [Usaco2006 Jan] Redundant Paths 分离的路径 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1132 Solv ...
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 554 Solved: 346[ ...
- BZOJ1612: [Usaco2008 Jan]Cow Contest奶牛的比赛
1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 645 Solved: 433 ...
随机推荐
- Java实现网页截屏
原文:http://www.open-open.com/code/view/1424006089452 import java.awt.AWTException; import java.awt.De ...
- OSX: 第三方部署Profile的方法和比較
眼下至少有三个第三方部署Profile的方法. 一个Profile Handler, 是利用Launchd对制定文件夹改变而激活的机制,把须要的profiles文件斗存放在制定目标机器的文件夹内,系统 ...
- oracle统计信息
手工刷ORACLE统计信息 select count(1) from LOG_TRX_DETAIL; select * from user_tab_statistics where table_n ...
- Python的调用程序
任务 调用系统命令ping 判断局域网内有哪些主机存活 假设你用c语言写了一个算法,需要对该算法进行测试.测试的数据集几百个.这时可以使用过GCC生成test.exe,再使用python批量调用该ex ...
- ios archives 出现的是other items而不是iOS Apps的解决方案
ios archives 出现的是other items而不是iOS Apps的解决方案 项目打包时出现的是不是出现在iOS Apps栏目下面,而是Other Items而且右边对应的Upload t ...
- github相关
1 某次release的源码 某次release的源码在release列表中,不在branch中,tag和release是在一起的.所以,下载某个release的源码应该去release中找,而不应该 ...
- File to byte[] in Java
File to byte[] in Java - Stack Overflow https://stackoverflow.com/questions/858980/file-to-byte-in-j ...
- 包管理 import debug 模块管理 module
import sys, os this_file_abspath = os.path.dirname(os.path.abspath(__file__)) ProjectUtil_path = '{} ...
- “千千静听”滚动标题栏,非常简单!(时间器控制窗口标题栏文字,然后赋值给Application.Title)
记得曾写过类似功能,但由于对Delphi数据类型不清楚,要花不少代码去处理中文被切半而出现乱码的尴尬.后来知道只需把字符串定义成 WideString 即可解决半个中文的问题了. 实现过程:不停地剪切 ...
- Test redis
单机测试: public class RedisClient{ private Jedis jedis; private JedisPool jedisPool; private ShardedJed ...