link:http://poj.org/problem?id=3181

本来很常规的一道完全背包,比较有意思的一点是,结果会超int,更有意思的解决方法是,不用高精度,用两个整型的拼接起来就行了。ORZ

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
typedef unsigned long long ULL;
ULL dp[], dp1[];
int main(void) {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r",stdin);
#endif
ULL tmp = ;
for (int i = ; i < ; ++i) tmp*=;
int n, k;
while (cin>>n>>k) {
memset(dp,,sizeof(dp));
memset(dp1,,sizeof(dp1));
dp[] = ;
for (int i = ; i <= k; ++i) {
for (int j=i; j<= n; ++j) {
dp1[j] += (dp1[j-i] + (dp[j]+dp[j-i])/tmp);
dp[j] = (dp[j]+dp[j-i])%tmp;
}
}
if (dp1[n]) cout<<dp1[n];
cout<<dp[n]<<endl;
}
return ;
}

o(╯□╰)o

poj3181 Dollar Dayz ——完全背包的更多相关文章

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

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

  2. poj3181 Dollar Dayz

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

  3. POJ 3181 Dollar Dayz ( 完全背包 && 大数高精度 )

    题意 : 给出目标金额 N ,问你用面额 1~K 拼成 N 的方案有多少种 分析 : 完全背包的裸题,完全背包在 DP 的过程中实际就是列举不同的装填方案数来获取最值的 故状态转移方程为 dp[i] ...

  4. poj 3181 Dollar Dayz(完全背包)

    Dollar Dayz Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2054 Descr ...

  5. Dollar Dayz(大数母函数,高低位存取)

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

  6. (完全背包 大数)Dollar Dayz (POJ 3181)

    http://poj.org/problem?id=3181 Description Farmer John goes to Dollar Days at The Cow Store and disc ...

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

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

  8. POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)

    首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...

  9. poj 3181 Dollar Dayz(求组成方案的背包+大数)

    可能nyist看见加的背包专题我老去凑热闹,觉得太便宜我了.他们新加的搜索专题居然有密码. 都是兄弟院校嘛!何必那么小气. 回到正题,跟我写的上一篇关于求组成方案的背包思路基本一样,无非就是一个二维费 ...

随机推荐

  1. Caffe + Ubuntu 14.04 64bit + CUDA6.5 + 无GPU 配置

    官网: http://caffe.berkeleyvision.org/installation.html#compilation 参考网站: http://www.cnblogs.com/dupul ...

  2. const char* && string && String^ 类型转换

    const char* && string && String^ 类型转换 const char* ---> string const char * cw= &q ...

  3. cellery ImportError & AttributeError

    一.zz的问题 celery 运行work要进入到 文件所在的文件夹下执行 二.AttributeError: 'Flask' object has no attribute 'user_option ...

  4. [css] 页面重构“鑫三无准则” 之“无宽度”准则

    原创文章,转载请注明来自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com]本文地址:http://www.zhangxinxu.com/wordpress/?p=1152 一 ...

  5. 【转载,整理】域名CNAME解析配置,使用域名B作为域名A的CNAME记录值

    最近有个需求,未备案的域名A,想解析到香港 或 国内的服务器上,但是由于未备案,直接使用cdn解析在国内访问会很慢 但是不想直接直接到ip,所以找到两个方法可以解决: 方案一:转移到其他服务器做301 ...

  6. selenium eclipse环境搭建

    1.python 3.5下载及安装 2.setuptools 与pip 下载地址是:http://pypi.Python.org/pypi/setuptools http://pypi.Python. ...

  7. POJ----(3974 )Palindrome [最长回文串]

    Time Limit: 15000MS   Memory Limit: 65536K Total Submissions: 5121   Accepted: 1834 Description Andy ...

  8. javascript new

    1. 仅function可以使用new 2. function使用new时,会拷贝function中this的内容给新对象,并将function的prototype指向新对象(如果该function没 ...

  9. 读《程序员的SQL金典》[3]--表连接、子查询

    一.表连接-JOIN 1. 自连接实例 查询类型相同的订单信息. SELECT O1 .*,O2.* FROM T_Order O1 JOIN T_Order O2 ON O1 .FTypeId= O ...

  10. zookeeper学习系列:二、api实践

    上一章我们知道zookeeper的简介,启动,设置节点以及结构性能.本小节我们来玩玩api,获取下数据. php版本: http://anykoro.sinaapp.com/2013/04/05/%E ...