Dollar Dayz
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5655   Accepted: 2125

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).

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
题解:母函数的裸题;但是一交就Wa;最终看了discuss,原来是大数;又不是太大,高低位存下,然而还是Wa,因为MOD还是开小了,MOD开到10^18次方才A;协会大神真是吊,这题
我不看题解肯定想不到会是大数。。。
代码:
extern "C++"{
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL; void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(LL &x){scanf("%lld",&x);}
void SI(char *x){scanf("%s",x);}
#define MOD 1000000000000000000
}
const int MAXN = ;
struct Node{
LL h,l;
};
Node a[MAXN],b[MAXN];
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
mem(a,);mem(b,);
for(int i = ;i <= n;i++)a[i].l = ;
for(int i = ;i <= k;i++){
for(int j = ;j <= n;j++){
for(int t = ;j + t <= n;t += i){
b[j + t].l += a[j].l;
b[j + t].h += a[j].h;
b[j + t].h += b[j + t].l / MOD;
b[j + t].l %= MOD;
}
}
for(int j = ;j <= n;j++){
a[j].h = b[j].h;
a[j].l = b[j].l;
b[j].h = ;
b[j].l = ;
}
}
if(a[n].h)
printf("%lld",a[n].h);
printf("%lld\n",a[n].l);
}
return ;
}

Dollar Dayz(大数母函数,高低位存取)的更多相关文章

  1. POJ 3181 Dollar Dayz(全然背包+简单高精度加法)

    POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...

  2. 字节的高低位知识,Ascii,GB2312,UNICODE等编码的关系与来历

    很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物.他们看到8个开关状态是好的,于是他们把这称为"字节". 再后来,他们又做了一些可以处理 ...

  3. .net下简单快捷的数值高低位切换

    .net下简单快捷的数值高低位切换 做网络通讯中数值传输是很普遍的事情,但数值的存储在不平台和硬件上存储方式都不一样,主要有两大类分别是高位和低位存储:而.net平台下是低位存储,通过.net提供的函 ...

  4. C语言如何分离一个数的高低位,如何将2个字节变成一个字节

    关于这个概念,是我从工作中学习的,虽然在读书的时候就应该要掌握,但是在开发中,这项技能尤其重要.我是做嵌入式开发的,在嵌入式开发过程中,如何对数据操作必然是不可缺少的问题,接下来,我们来看一个例子: ...

  5. C语言之linux内核实现位数高低位互换

    linux内核实在是博大精深,有很多优秀的算法,我之前在工作中就遇到过位数高低位交换的问题,那时候对于C语言还不是很熟练,想了很久才写出来.最近在看内核的时候看到有内核的工程师实现了这样的算法,和我之 ...

  6. P1100 高低位交换

    题目描述 给出一个小于2^{32}232的正整数.这个数可以用一个3232位的二进制数表示(不足3232位用00补足).我们称这个二进制数的前1616位为“高位”,后1616位为“低位”.将它的高低位 ...

  7. 【洛谷P1100】高低位交换

    高低位交换 题目链接 这道题非常水,我是用位运算做的 a=n>>16 二进制的“高位”b=n-(a<<16) 二进制的“低位”ans=(b<<16)+a 转换 #i ...

  8. 洛谷——P1100 高低位交换

    P1100 高低位交换 题目描述 给出一个小于2^32的正整数.这个数可以用一个32位的二进制数表示(不足32位用0补足).我们称这个二进制数的前16位为“高位”,后16位为“低位”.将它的高低位交换 ...

  9. 洛谷 P1100 高低位交换

    P1100 高低位交换 题目描述 给出一个小于2^32的正整数.这个数可以用一个32位的二进制数表示(不足32位用0补足).我们称这个二进制数的前16位为“高位”,后16位为“低位”.将它的高低位交换 ...

随机推荐

  1. 电子科大POJ "统计单词"

    统计单词 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) C-sources: ...

  2. java多线程 并发 编程

    转自:http://www.cnblogs.com/luxiaoxun/p/3870265.html 一.多线程的优缺点 多线程的优点: 1)资源利用率更好 2)程序设计在某些情况下更简单 3)程序响 ...

  3. hdu 3681 Prison Break(状态压缩+bfs)

    Problem Description Rompire . Now it’s time to escape, but Micheal# needs an optimal plan and he con ...

  4. 【Java面试】基础知识篇

    [Java面试]基础知识篇 Java基础知识总结,主要包括数据类型,string类,集合,线程,时间,正则,流,jdk5--8各个版本的新特性,等等.不足的地方,欢迎大家补充.源码分享见个人公告.Ja ...

  5. FP-Growth算法之频繁项集的挖掘(python)

    前言: 关于 FP-Growth 算法介绍请见:FP-Growth算法的介绍. 本文主要介绍从 FP-tree 中提取频繁项集的算法.关于伪代码请查看上面的文章. FP-tree 的构造请见:FP-G ...

  6. Collections你用对了吗?

    .Net有两类基础的集合类型:List和Dictionary.List是基于Index的,Dictionary是基于key的.集合类型一般实现了IEnumberable,ICollection或者Il ...

  7. linux下 /etc/profile、~/.bash_profile ~/.profile的执行过程

    关于登录linux时,/etc/profile.~/.bash_profile等几个文件的执行过程. 在登录Linux时要执行文件的过程如下: 在刚登录Linux时,首先启动 /etc/profile ...

  8. cc1plus: fatal error: emeralddb-pmdMain.d: No such file or directory

    签名autoscan, aclocal, config啥的都没错,最后make 报下面的错,查了各个文件没发现有啥问题,请哪位帮忙卡看 make[1]: Entering directory `/ro ...

  9. Asp.net MVC razor语法参考

    Razor语法的快捷参考http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx/ 只是copy下来便于查阅! I ...

  10. DataSet 图解

    DataSet层次结构中的类请参见表所示: 类 说明 DataTableCollection 包含特定数据集的所有DataTable对象 DataTable 表示数据集中的一个表 DataColumn ...