[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 ...
随机推荐
- ArcGIS Engine 中的绘制与编辑
1.线段绘制 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x, y); 2. 创建 IPoi ...
- 查看linux接口进出口流量的命令;linux 网络监控;流量监控
1.nload,左右键切换网卡 2.sudo iftop 3.sudo iptraf 按连接/端口查看流量 4.sudo nethogs: 按进程查看流量占用 5.ss: 连接查看工具 6.dstat ...
- [Javascript] Use JavaScript's for-in Loop on Objects with Prototypes
Loops can behave differently when objects have chained prototype objects. Let's see the difference w ...
- Spring AOP监控SQL运行
对数据库连接池Proxool比較熟悉的读者,都知道Proxool能够记录SQL运行内容和时间等信息日志. 我们能够将该日志记录专门的SQL日志文件.对于查找运行特别耗时的SQL起了不小的作用. 对于一 ...
- 李洪强iOS开发之录音和播放实现
李洪强iOS开发之录音和播放实现 //首先导入框架后,导入头文件.以下内容为托控件,在storyboard中拖出两个按钮为录音和播放按钮 //创建一个UIViewController在.h文件中写 # ...
- Xcode6 设置LaunchImage图标
最近设置LaunchImage图标时发现怎么都没有效果,后来发现是Xcode6中新建项目的时候会默认添加一个LaunchScreen.xib的文件,我们启动程序的时候也会发现,加载的时LaunchSc ...
- Hackrank Equal DP
Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. ...
- slf4j的总结
参考文章 log4j2使用总结 slf4j介绍以及实现原理窥探 使用Slf4j集成Log4j2构建项目日志系统的完美解决方案 slf4j(全称是Simple Loging Facade For Jav ...
- ranlib
1 ranlib的缩写 random access library 2 ranlib的作用 为静态库的符号建立索引,可以加速链接,因此称用ranlib处理过的library为random access ...
- 《31天成为IT服务达人》--做事篇(第四章)之如何找目标
前面介绍了什么是IT服务.以下几章将介绍IT服务该怎么做.在聊怎么做之前.想起几句流行的告白和准备入行IT服务事业的朋友共勉. 当你的才华 还撑不起你的野心时 就应该静下心来 学习 --- 当你 ...