POJ3181 Dollar Dayz 【母函数】+【高精度】
来源:互联网 发布:电磁仿真软件 feko 编辑:程序博客网 时间:2024/05/16 15:11
Dollar Dayz
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4204 Accepted: 1635
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$1Write 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).
Input
A single line with two space-separated integers: N and 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
Source
USACO 2006 January Silver
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;#define maxn 1002typedef long long LL;const LL UP = 1e18;//1000000000000000000;struct Node { LL u, v; Node(LL x = 0, LL y = 0) { u = x; v = y; } friend Node operator + (Node a, Node b) { a.u += b.u; a.v += b.v; if(a.v >= UP) { a.v -= UP; ++a.u; } return a; }} c1[maxn], c2[maxn], a, b(0, 1);int main() { int N, K, i, j, k; scanf("%d%d",&N, &K); c1[0] = b; for(i = 1; i <= K; ++i) { for(j = 0; j <= N; ++j) for(k = 0; k + j <= N; k += i) c2[j+k] = c2[j+k] + c1[j]; for(j = 0; j <= N; ++j) { c1[j] = c2[j]; c2[j] = a; } } if(c1[N].u) printf("%lld%017lld\n", c1[N].u, c1[N].v); else printf("%lld\n", c1[N].v); return 0;}
0 0
- POJ3181 Dollar Dayz 【母函数】+【高精度】
- POJ3181-Dollar Dayz-完全背包+高精度
- poj3181 Dollar Dayz dp
- POJ3181 Dollar Dayz
- poj3181 Dollar Dayz
- 【POJ3181】【Dollar Dayz】
- 【POJ3181】【Dollar Dayz】
- POJ3181--Dollar Dayz
- POJ3181 Dollar Dayz
- POJ3181 Dollar Dayz(DP)
- POJ3181 Dollar Dayz
- POJ3181 Dollar Dayz
- POJ3181-Dollar Dayz
- POJ3181:Dollar Dayz(完全背包)
- poj3181 Dollar Dayz (DP+大数)
- POJ3181 Dollar Dayz-完全背包问题-高精度(大数)处理(附测试数据)
- POJ3181 Dollar Dayz 动态规划,多重背包
- 【转】POJ3181——Dollar Dayz(完全背包优化)
- HDU—— 5123 who is the best?
- linux内核编译与简易驱动
- C语言中传值问题
- dede 0day 利用小技巧
- layout_weight
- POJ3181 Dollar Dayz 【母函数】+【高精度】
- Python的感悟笔记
- nyoj205求余数(大整数求模)
- android 视频录制 例子源码
- Zigbee协议规范--数据传输原语流图及说明(
- 老公出轨还放言天下男人都偷吃
- linux虚拟进程地址映射机制
- 猜数字大小
- Java分页显示