[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 ...
随机推荐
- Oracle冷备和热备脚本
Oracle冷备和热备脚本 冷备脚本: set feedback off set heading off set verify off set trimspool off set echo off ...
- 静态网页怎样实现动态交互?-JavaScript
在Html基础上,javascript能够开发交互式web网页.javascript的出现使得网页和用户之间实现了一种实时性的.动态的.交互性的关系,javascript短小精悍,又是在客户机上执行的 ...
- linux core文件设置
http://blog.csdn.net/ctthuangcheng/article/details/8963551 linux core文件设置 分类: Linux OS Debugging Te ...
- Essay
要养成先连续输入一对匹配的字符——比如"("和")",以及"{"和"}"——再在其中填写内容的习惯.如果先填写内容,很容 ...
- 每天复习Shell—ls
ls命令是linux下最经常使用的命令.ls命令就是list的缩写缺省下ls用来打印出当前文件夹的清单假设ls指定其它文件夹那么就会显示指定文件夹里的文件及文件夹清单. 通过ls 命令不仅能够查 ...
- 设置ArcGIS的数据源
我从别的地方拿到一份现成的地图文档(*.mxd),在该服务器上运行得好地地,图文并茂,但用我自己机器的arcMap打开就一片空白,啥都没有. 看左边的各个图层目录,图标上都有个粉红色的惊叹号,醒悟过来 ...
- Koa2学习(一)环境搭建
Koa2学习(一)环境搭建 koa2脚手架 koa2服务安装 koa2-generator目录结构 什么是 Koa2 koa 是由 Express 原班人马打造的,致力于成为一个更小.更富有表现力.更 ...
- is id() == 从内存的最小化占用角度解释 我是孕育者,我也应该这样设计 变,必然伴随着加法 一个list是否可以执行set()
def f(a, b): print(a is b, b is a, a == b, a.__eq__(b), id(a), id(b)) f(2, 2) f([2], [2]) f('2', '2' ...
- RFC 在OA中创建PR
创建PR:BAPI_REQUISITION_CREATE BAPI_PR_CREATE "Create Enjoy Purchase Requisistion ...
- 【转】wait和waitpid详解
发现进程有关的编程题里面的包含知识量实在是太庞大,这是关于wait和waitpid区别的,以前只是粗略知道它们的区别,这是网上看到的比较全的对比 转自http://blog.chinaunix.net ...