poj3181 Dollar Dayz ——完全背包
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 ——完全背包的更多相关文章
- POJ 3181 Dollar Dayz(全然背包+简单高精度加法)
POJ 3181 Dollar Dayz(全然背包+简单高精度加法) id=3181">http://poj.org/problem?id=3181 题意: 给你K种硬币,每种硬币各自 ...
- poj3181 Dollar Dayz
Description Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of to ...
- POJ 3181 Dollar Dayz ( 完全背包 && 大数高精度 )
题意 : 给出目标金额 N ,问你用面额 1~K 拼成 N 的方案有多少种 分析 : 完全背包的裸题,完全背包在 DP 的过程中实际就是列举不同的装填方案数来获取最值的 故状态转移方程为 dp[i] ...
- poj 3181 Dollar Dayz(完全背包)
Dollar Dayz Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5419 Accepted: 2054 Descr ...
- Dollar Dayz(大数母函数,高低位存取)
Dollar Dayz Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5655 Accepted: 2125 Descr ...
- (完全背包 大数)Dollar Dayz (POJ 3181)
http://poj.org/problem?id=3181 Description Farmer John goes to Dollar Days at The Cow Store and disc ...
- 【BZOJ】1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(背包+高精度)
http://www.lydsy.com/JudgeOnline/problem.php?id=1655 背包就没什么好说的了,裸的完全背包.. 但是我一开始交开了ull都wa了T_T.. 精度太大. ...
- POJ 3181 Dollar Dayz && Uva 147 Dollars(完全背包)
首先是 Uva 147:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_p ...
- poj 3181 Dollar Dayz(求组成方案的背包+大数)
可能nyist看见加的背包专题我老去凑热闹,觉得太便宜我了.他们新加的搜索专题居然有密码. 都是兄弟院校嘛!何必那么小气. 回到正题,跟我写的上一篇关于求组成方案的背包思路基本一样,无非就是一个二维费 ...
随机推荐
- CentOS6.5 mysql 5.5安装
CentOS 6 mysql5.5安装配置 1 安装所需软件 2 安装cmake 3 tar.gz形式安装mysql 4 配置与启动 MySQL自5.5版本以后,就开始使用cmake编译工具了.tar ...
- 学习mongo系列(十一)关系
准备工作:首先在maxh数据库的address集合中先插入数据 > db.address.insert({child_address:"gansu"}) WriteResul ...
- [http session]
原文链接:http://lavasoft.blog.51cto.com/62575/275589/ 1.Session创建的时间是: 一个常见的误解是以为session在有客户端访问时就被创建,然而事 ...
- angular.js学习笔记
1.带ng-repeat的标签 会重复这个标签及其内部的内容,直至x循环完 比如 <tr ng-repeat="x in names | orderBy : 'Name'" ...
- Hibernate实现向数据库插入一条数据全过程(Study By Example)
1.数据库(直接在cmd下进入数据库操作亦可) (1)启动Navicat for MySQL (2)打开连接,创建一个数据库,名为testdb (3)新建表user1,表结构如图所示 2.数据库池 ( ...
- 深入理解 AngularJS 的 Scope
JavaScript 的原型继承就是奇葩. 之前在 V2EX 上看到讨论说,不会 OOP 的 JavaScript 的程序员就是野生程序员.看来我是属于野生的. 一.遇到的问题 问题发生在使用 A ...
- 树(一)——线段树
问题 现在有1~30这30个数,数N被抽上的概率正比于1/sqrt(N+1),求满足这个概率分布的随机数发生器. 思路 第一,如何解决这个"概率正比"问题. 第二,如何产生满足条件 ...
- 一个简单的数据查询显示jsp
以前使用jstl标签库只是使用core来显示一些数据,非常方便,今天看了下发现jstl还有其他的标签,使用都非常方便, 1.sql标签,可以直接访问数据库,后台代码都不需要了,这在某些时候非常适合使用 ...
- 倒计时js代码
<div class="time"> <span id="t_d">00天</span> <span id=" ...
- C#压缩文件夹
using System;using System.Collections.Generic;using System.Text; ///第三方dllusing ICSharpCode.SharpZip ...