[Usaco2006 Jan] Dollar Dayz 奶牛商店
来源:互联网 发布:warframe端口脱机 编辑:程序博客网 时间:2024/06/06 20:23
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 0x7f7f7ftypedef 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;}
阅读全文
0 0
- bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店
- 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店
- [Usaco2006 Jan] Dollar Dayz 奶牛商店
- 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店 (完全背包+高精度)
- BZOJ 1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店 完全背包
- BZOJ 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店 dp+高精度
- |BZOJ 1655|无限背包|高精度|[Usaco2006 Jan] Dollar Dayz 奶牛商店
- bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店(完全背包+高精)
- bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(高精度完全背包)
- BZOJ 1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店 01背包+高精度
- Dollar Dayz
- BZOJ 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- bzoj1654 [Usaco2006 Jan]The Cow Prom 奶牛舞会
- bzoj1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- [BZOJ1654] [Usaco2006 Jan]The Cow Prom 奶牛舞会
- 【BZOJ】1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会
- BZOJ 1635: [Usaco2006 Jan]The Cow Prom 奶牛舞会 tarjan
- 每日一练18
- SHELL字符串处理技巧(${}、##、%%)
- hdu4405(期望dp)
- 大数据Spark08_SparkSql
- 有谁和我一样被38号的功率扭矩骗了的么?---普通正常人买车如何看发动机参数
- [Usaco2006 Jan] Dollar Dayz 奶牛商店
- CSS 基础
- 卖橙子的程序
- PendingIntent
- Linux下如何进行SFTP用户权限设置
- python 使用__slots__
- java.lang.OutOfMemoryError:PermGen space tomcat7 内存溢出
- WKWebView如何实现post请求
- VB6 调取EXCEL 打印时指定 打印范围和打印份数