http://www.lydsy.com/JudgeOnline/problem.php?id=1655

背包就没什么好说的了,裸的完全背包。。

但是我一开始交开了ull都wa了T_T。。

精度太大。。。

。。

打高精度吧。。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int M=1005;
int n, k;
int f[M][M]; void add(int a[], int b[]) {
int lena=a[0], lenb=b[0], lenc=max(lena, lenb);
int k=0, i;
for(i=1; i<=lenc || k; ++i) {
k=(a[i]+b[i])/10;
a[i]+=b[i]; a[i]%=10;
a[i+1]+=k;
}
a[0]=i-1;
} int main() {
read(n); read(k);
f[0][1]=f[0][0]=1;
for1(i, 1, k) {
for1(j, i, n)
add(f[j], f[j-i]);
}
int t=f[n][0];
for3(i, t, 1) print(f[n][i]);
return 0;
}

Description

Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly $5 to spend. He can buy 5 tools at $1 each or 1 tool at $3 and an additional 1 tool at $2. Of course, there are other combinations for a total of 5 different ways FJ can spend all his money on tools. Here they are: 1 @ US$3 + 1 @ US$2 1 @ US$3 + 2 @ US$1 1 @ US$2 + 3 @ US$1 2 @ US$2 + 1 @ US$1 5 @ US$1 Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).

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

HINT

Source

【BZOJ】1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(背包+高精度)的更多相关文章

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

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

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

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

  3. [Usaco2006 Jan] Dollar Dayz 奶牛商店

    Description 约翰到奶牛商场里买工具.商场里有K(1≤K≤100).种工具,价格分别为1,2,-,K美元.约翰手里有N(1≤N≤1000)美元,必须花完.那他有多少种购买的组合呢? Inpu ...

  4. 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 & ...

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

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

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

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

  7. Bzoj 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛 传递闭包,bitset

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

  8. BZOJ 1612: [Usaco2008 Jan]Cow Contest奶牛的比赛( floyd )

    对于第 i 头牛 , 假如排名比它高和低的数位 n - 1 , 那么他的 rank 便可以确定 . floyd -------------------------------------------- ...

  9. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

随机推荐

  1. JUC同步器框架AbstractQueuedSynchronizer源码图文分析

    JUC同步器框架AbstractQueuedSynchronizer源码图文分析 前提 Doug Lea大神在编写JUC(java.util.concurrent)包的时候引入了java.util.c ...

  2. android安装应用程序工具类

    /** * 安装APK文件 *@param APK文件 *Version: *author:YangQuanqing */ private void installAPK(File file){ // ...

  3. js Object.defineProperty 使用

    语法 Object.defineProperty(obj, prop, descriptor) 参数说明: obj:必需.目标对象 prop:必需.需定义或修改的属性的名字descriptor:必需. ...

  4. webpack 编译html模板文件

    1.项目结构 安装loader: npm i html-loader --save-dev npm i ejs-loader --save-dev 2.模板文件layer.html <div c ...

  5. js 实现图片的无缝滚动

      js 实现图片的无缝滚动 CreateTime--2018年3月7日17:18:34 Author:Marydon 测试成功 <!DOCTYPE html> <html> ...

  6. excel 根据单元格内容自动调整列宽

      excel 根据单元格内容自动调整列宽 CreateTime--2018年5月28日08:49:40 Author:Marydon 1.情景展示 单元格宽度超过了列宽 2.解决方案 第一步:同时选 ...

  7. XMPP协议实现即时通讯底层书写 (二)-- IOS XMPPFramework Demo+分析

    我希望,This is a new day! 在看代码之前,我认为你还是应该先整理一下心情,来听我说几句: 首先,我希望你是在早上边看这篇blog,然后一边開始动手操作,假设你仅仅是看blog而不去自 ...

  8. myeclipse2014安装jad反编译插件

    myeclipse上默认不能查看class文件,需要查看的话安装反编译插件 安装步骤: 准备图中框里的两个文件 1. [net.sf.jadclipse_3.3.0.jar]文件拷贝到如下路径([D: ...

  9. 【LeetCode】162. Find Peak Element (3 solutions)

    Find Peak Element A peak element is an element that is greater than its neighbors. Given an input ar ...

  10. Quartz 2D中CGContextSaveGState与UIGraphicsPushContext

    CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Context是图形上下文 ...