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

就是很水的完全背包

f[j]=f[j]+f[j - i]

一开始以为是部分背包,然后样例都过不了……

改成完全背包又wa了……

结果发现USACO数据里有20多位的答案……

没办法改高精度吧……

#include<cstdio>
struct bignum{
int len;
int a[100];
}f[1001];
int n,k;
inline int max(int a,int b)
{return a>b?a:b;}
inline int min(int a,int b)
{return a<b?a:b;}
inline void add(int i,int j,bignum &k)
{
bignum ans;
ans.len=max(f[j-i].len,f[j].len);
for (int l=1;l<=ans.len;l++)
ans.a[l]=f[j-i].a[l]+f[j].a[l];
ans.a[ans.len+1]=0;
for (int l=1;l<=ans.len;l++)
{
ans.a[l+1]+=ans.a[l]/10;
ans.a[l]%=10;
}
if (ans.a[ans.len+1])ans.len++;
k.len=ans.len;
for (int i=1;i<=ans.len;i++)
k.a[i]=ans.a[i];
}
int main()
{
scanf("%d%d",&n,&k);
f[0].len=f[0].a[1]=1;
for (int i=1;i<=min(n,k);i++)
for (int j=i;j<=n;j++)
add(i,j,f[j]);
for (int i=f[n].len;i>=1;i--)
printf("%d",f[n].a[i]);
}

bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店的更多相关文章

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

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

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

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

  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. Windows系统结构

    四种用户模式进程:1.系统支持进程,比如登录进程和会话管理器,并不是Windows服务,不有服务控制管理器启动2.服务进程,一些以Windows服务方式来运行的组件3.用户应用进程4.环境子系统服务器 ...

  2. 升级 pip版本

    安装第三方库:pip install Pillow 出现 You are using pip version 7.1.2, however version 9.0.1 is available. Yo ...

  3. pyqt一个小例子

    # -*- coding: utf-8 -*- __author__ = 'Administrator' from PyQt4 import Qt,QtCore,QtGui import sys,ra ...

  4. Eclipse UML插件AmaterasUML的配置及使用

    AmaterasUML是个人觉得最好用的Eclipse UML插件,可以通过拖拽Java源文件,轻松生成类图结构,同时支持活动图.时序图和用例图.它的官方下载地址是:http://sourceforg ...

  5. python 安装 memcache

    方式一: python3 -m pip install python-memcached 方式二: pip3 install python-memcached 方式三: tar zxf python- ...

  6. 将16进制(HTML)颜色值转换成 Color类型

    private void btnChangeColor_Click(object sender, EventArgs e) { txtColor.BackColor = ColorTranslator ...

  7. 关于asp.net的<%#%>的一些总结

    一.说明 asp特有的控件在前台绑定数据的语法,且必须要调用该控件的DataBind()方法才执行,也可以整个页面数据绑定. 二.注意 1.并不是只有服务器控件才可以使用该语法,当整个页面调用this ...

  8. Katana概述

    OWIN owin是web services和framework组件之间的抽象.抽象包括两个核心要素: environment dictionary 这个数据结构存储处理HTTP请求必须的状态和相关的 ...

  9. T4文本模板

    <#...#> 可以包含语句 <#=...#>  用于表达式,提供“输出”操作 <#+ ...> 使用类功能控制块向文本模板添加方法.属性.字段,必须作为文件中最后 ...

  10. c#转码解码

    ///反转码                          mdata[k].MNAME = unescape(mdata[k].MNAME);程家楠 13:51:00 Microsoft.JSc ...