思路:

题目链接http://poj.openjudge.cn/practice/C18A/

先说一个结论,每一天要么7要么0,由此提供一种状态压缩dp的解法。

实现:

 #include <bits/stdc++.h>
using namespace std;
const int MAXN = , INF = 0x3f3f3f3f;
int a[MAXN], dp[][ << ];
int main()
{
int t, n;
cin >> t;
while (t--)
{
cin >> n;
int msk = ( << ) - ;
memset(dp, 0x3f, sizeof dp);
for (int i = ; i <= n; i++) cin >> a[i];
for (int i = ; i < << ; i++) dp[][i] = ;
for (int i = ; i < n; i++)
{
memset(dp[i + & ], 0x3f, sizeof dp[i + & ]);
for (int j = ; j < << ; j++)
{
int tmp = j << & msk;
dp[i + & ][tmp | ] = min(dp[i + & ][tmp | ],
dp[i & ][j] + * a[i + ]);
if (i >= && !tmp) continue;
dp[i + & ][tmp] = min(dp[i + & ][tmp], dp[i & ][j]);
}
}
int minn = INF;
for (int i = ; i < << ; i++) minn = min(minn, dp[n & ][i]);
cout << minn << endl;
}
return ;
}

PKU_campus_2018_A Wife的更多相关文章

  1. wife信号如何传播

    方法一:像哈利波特一样穿墙而出 无论是wife信号还是广播信号本质上都属于电磁波.x光穿透力强所以可以穿透人体给体内照相,但是wife信号作为电磁波虽然也可以穿透墙而过,但是他的穿透能力实在是太弱了. ...

  2. How I explained OOD to my wife(转)

    How I explained OOD to my wife Learning Object Oriented Design principles through interesting conver ...

  3. 【The Time Traveller's Wife】

    After reading The Time Traveller's Wife:      It's a tragedy,I think.But it's mixed with hope.Henry ...

  4. 傲骨贤妻第一季/全集The Good Wife迅雷下载

    第一季 The Good Wife Season 1 (2009)看点:在经受丈夫Peter的背叛以及因此而带来的公众羞辱后,Alicia Florrick选择重新继续自己原来的事业,一名辩护律师,以 ...

  5. Why I Want A Wife

    I want a wife who will take care of my physical needs. I want a wife who will keep my house clean. A ...

  6. How I explained Design Patterns to my wife: Part 1

    Introduction Me and my wife had some interesting conversations on Object Oriented Design principles. ...

  7. How I explained OOD to my wife

    Introduction My wife Farhana wants to resume her career as a software developer (she started her car ...

  8. PKU campus 2018 A Wife——差分约束?/dp

    题目:http://poj.openjudge.cn/campus2018/A 有正规的差分约束做法,用到矩阵转置等等. 但也有简单(?)的dp做法. 有一个结论(?):一定要么在一天一点也不选,要么 ...

  9. PKUACM2018 A Wife——DP

    题目:http://poj.openjudge.cn/practice/C18A/ 据说正解是差分约束,转化的过程还要用到标准型.对偶型什么的知识,暂时还不太懂... 但也有贪心DP做法,有个结论:一 ...

随机推荐

  1. HashTable HashMap区分

    主要是安全.速度: 1.HashMap可以接受null的键. 2.HashMap是非synchronized,而Hashtable是synchronized,这意味着Hashtable是线程安全的,多 ...

  2. 使用proc接口例子【转】

    本文转载自:http://blog.csdn.net/mike8825/article/details/52434666 版权声明:本文为博主原创文章,未经博主允许不得转载. 在上一篇的使用sys接口 ...

  3. CVE-2015-7547漏洞分析从原因到利用到补丁(非常适合小白)【转】

    本文转载自:http://blog.csdn.net/u012406115/article/details/72232535 一.         漏洞概述 CVE漏洞链接:http://www.cv ...

  4. async-await原理解析

    在用async包裹的方法体中,可以使用await关键字以同步的方式编写异步调用的代码.那么它的内部实现原理是什么样的呢?我们是否可以自定义await以实现定制性的需求呢?先来看一个简单的例子: cla ...

  5. codeforces 690D1 D1. The Wall (easy)(dfs)

    题目链接: D1. The Wall (easy) time limit per test 0.5 seconds memory limit per test 256 megabytes input ...

  6. codeforces 414A A. Mashmokh and Numbers(素数筛)

    题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...

  7. 实现自定义xib和storyboard的加载,

    一:加载xib 1.分别创建xib,.h  .m文件继承自UIView. 在xib上绑定类名. 或者创建文件的时候直接勾选xib 2.在控制器中调用类方法 jyq52787网盘/ios/潭州学院/iO ...

  8. cocos2d-x 坐标系解惑

    1.CCTouch* touch->getLocation() ---- 返回当前触摸点在openGL坐标系中的位置 openGL坐标系,原点在左下角,x向右为正,y向上为正. 2.CCTouc ...

  9. python __builtins__ staticmethod类 (64)

    64.'staticmethod', 返回静态方法 class staticmethod(object) | staticmethod(function) -> method | | Conve ...

  10. bzoj 5210: 最大连通子块和【动态dp+树剖+线段树+堆】

    参考:https://www.cnblogs.com/CQzhangyu/p/8632904.html 要开longlong的 首先看dp,设f[u]为必选u点的子树内最大联通块,p[u]为不一定选u ...