[USACO 2012 Jan Silver] Bale Share【DP】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=107
没想到太不应该了,真的不应该啊!
f[i][j][k]表示前i个包,第一个包里共有j大小的物品,第二个包里共有k大小的物品是否成立,则方程为:
f[i][j][k] = f[i - 1][j - a[i]][k] || f[i - 1][j][k - a[i]] || f[i - 1][j][k];
观察方程,可以省去数组a改用单独一个变量,并使用滚动数组,详见代码。
#include <cstdio> const int maxn = ; int n, a, s, ans = ;
bool f[][]; inline int minn(int aa, int ss) {
return aa < ss? aa: ss;
}
inline int max3(int aa, int ss, int dd) {
aa = aa > dd? aa: dd;
return aa > ss? aa: ss;
} int main(void) {
freopen("baleshare.in", "r", stdin);
freopen("baleshare.out", "w", stdout);
scanf("%d", &n);
f[][] = true;
for (int i = ; i <= n; ++i) {
scanf("%d", &a);
s += a;
for (int j = s; j >= ; --j) {
for (int k = s - j; k >= ; --k) {
if (j >= a) {
f[j][k] = f[j][k] || f[j - a][k];
}
if (k >= a) {
f[j][k] = f[j][k] || f[j][k - a];
}
}
}
} for (int j = ; j <= s; ++j) {
for (int k = ; j + k <= s; ++k) {
if (f[j][k]) {
ans = minn(ans, max3(j, k, s - j - k));
}
}
}
printf("%d\n", ans);
return ;
}
为什么会变成这样呢,明明是一道水题。。。
[USACO 2012 Jan Silver] Bale Share【DP】的更多相关文章
- [USACO 2012 Jan Silver] Delivery Route【拆点】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=106 这道题还真是完全没思路,真的不知道怎么做,但是看了题解后恍然大悟. ...
- bzoj258 [USACO 2012 Jan Gold] Bovine Alliance【巧妙】
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=111 传送门2:http://www.lydsy.com/JudgeOn ...
- bzoj2581 [USACO 2012 Jan Gold] Cow Run【And-Or Tree】
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=110 传送门2:http://www.lydsy.com/JudgeOn ...
- bzoj 1575: [Usaco2009 Jan]气象牛Baric【dp】
完了不会dp了 设f[i][j]为以i结尾,有j个时的最优值,辅助数组g[i][j]为s选了i和j,i~j中的误差值 转移是f[j][i]=min(f[k][i-1]+g[k][j]) #includ ...
- bzoj 1700: [Usaco2007 Jan]Problem Solving 解题【dp】
很像贪心的dp啊 这个定金尾款的设定让我想起了lolita和jk制服的尾款地狱-- 设f[i][j]为从j到i的付定金的最早月份然后从f[k][j-1]转移来,两种转移f[i][j]=min(f[i] ...
- USACO翻译:USACO 2012 JAN三题(2)
USACO 2012 JAN(题目二) 一.题目概览 中文题目名称 叠干草 分干草 奶牛联盟 英文题目名称 stacking baleshare cowrun 可执行文件名 stacking bale ...
- USACO翻译:USACO 2012 JAN三题(1)
USACO 2012 JAN(题目一) 一.题目概览 中文题目名称 礼物 配送路线 游戏组合技 英文题目名称 gifts delivery combos 可执行文件名 gifts delivery c ...
- USACO翻译:USACO 2012 FEB Silver三题
USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...
- Kattis - honey【DP】
Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...
随机推荐
- [Node.js] Write or Append to a File in Node.js with fs.writeFile and fs.writeFileSync
In node.js, you can require fs, and then call fs.writeFile with the filename, and data to write to t ...
- [Bash] Search for Text with `grep`
In this lesson, we’ll use grep to find text patterns. We’ll also go over some of the flags that grep ...
- ADO.NET(OleDb)读取Excel表格时的一个BUG
如果我们有例如以下一个Excel表格: 如今要使用C#程序读取其内容: using System; using System.Data.OleDb; namespace Skyiv.Be ...
- Behavioral模式之Chain of Responsibility模式
1.意图 使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系,将这些对象连成一条链,并沿着这条链传递改请求,知道有一个对象处理它为止. 2.别名 无 3.动机 考虑一个图形用户界面 ...
- 在XX公司工作第二天,维护已有代码
根据<C++ More Exception>所述的规则: Rule #1: Never write using-directives in header files. Rule #2: N ...
- Android - 隐藏EditText弹出的软键盘输入(SoftInput)
隐藏EditText弹出的软键盘输入(SoftInput) 本文地址: http://blog.csdn.net/caroline_wendy 保持界面的整洁, 能够选择在进入界面时, 隐藏EditT ...
- php事务操作示例
<?php //数据库连接 $conn = mysql_connect('localhost', 'root', '');mysql_select_db('test', $conn); /* 支 ...
- Android碎纸机效果
1.总体思想 活用padding和margin 2.实现过程 public class PopupShredderView extends FrameLayout{ public PopupShred ...
- 嵌入式开发之davinci---dm8127 ipipe
http://blog.csdn.net/dog0138/article/details/4212576 http://e2e.ti.com/support/dsp/davinci_digital_m ...
- mongo14-----group,aggregate,mapReduce
group,aggregate,mapReduce 分组统计: group() 简单聚合: aggregate() 强大统计: mapReduce() db.collection.group(docu ...