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

据说正解是差分约束,转化的过程还要用到标准型、对偶型什么的知识,暂时还不太懂...

但也有贪心DP做法,有个结论:一个点要么没有,要么有7个小时(但不太会证明...);

然后就DP即可。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int const maxn=1e5+,inf=0x3f3f3f3f;
int T,n,a[maxn];
ll f[maxn];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d",&a[i]);
memset(f,0x3f,sizeof f);
f[]=;
for(int i=;i<=n;i++)
for(int j=max(,i-);j<i;j++)
f[i]=min(f[i],f[j]+*a[i]);
ll ans=inf;
for(int i=n;i>n-;i--)ans=min(ans,f[i]);
printf("%lld\n",ans);
}
return ;
}

PKUACM2018 A Wife——DP的更多相关文章

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

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

  2. 动态规划(计数DP):HDU 5136 Yue Fei's Battle

    Yue Fei's Battle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Other ...

  3. [hdu5136]Yue Fei's Battle 2014 亚洲区域赛广州赛区J题(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 现场赛的时候由于有个地方有点小问题,没有成功AC,导致与金牌失之交臂. 由于今天下 ...

  4. 51Nod 1092 回文字符串(LCS + dp)

    51Nod 1092 数据结构暑假作业上出现的一题,学习了一下相关算法之后,找到了oj测试能AC. 1.回文串是一种中心对称的结构,这道题可以转变为求最长回文子序列长度的题目.(子序列:可以不连续) ...

  5. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  6. hdu 1500 Chopsticks DP

    题目链接:HDU - 1500 In China, people use a pair of chopsticks to get food on the table, but Mr. L is a b ...

  7. URAL 1326. Bottle Taps(简单的状压dp)

    题目不太好读懂,就是先给你一个n代表要从n个物品中买东西,然后告诉你这n个东西的单位价格,在给你m个集合的情况.就是每一个结合中有x件物品.他们合起来买的价格是k.这x件物品依次是:p1--px.之后 ...

  8. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  9. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

随机推荐

  1. HDU多校Round 8

    Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...

  2. 运行容器出现docker: Error response from daemon: driver failed programming external connectivity on endpoint elegant_ptolemy (7fe85ca6bd744449ff82b81c1577d73b6821c4e51780c8238fad6aa0cb940522): (iptables fai

    运行容器时出现以下报错: docker: Error response from daemon: driver failed programming external connectivity on ...

  3. C++字符串处理函数总结

    1.基础函数输入输出:cin,cout,getchar,gets,putchar,puts,printf,scanf格式化:sprintf,sprintf_s,wsprintf,wsprintf_s, ...

  4. Go:内置函数

    一.内置函数 close // 主要用来关闭channel len // 用来求长度,比如string.array.slice.map.channel new // 用来分配内存,主要用来分配值类型, ...

  5. saturne installation on Ubuntu

    test installation Table of Contents 1. installation guide 1 installation guide saturne_installation. ...

  6. list tuple dict (列表,元祖,字典间的相互转换)

    #-*- coding:UTF-8 -*- #author:RXS002 #1.字典 dict = {'name':'Zara','age':7,'class':'First'} #字典转换为字符串, ...

  7. 为什么要有uboot?带你全面分析嵌入式linux系统启动过程中uboot的作用

    1.为什么要有uboot 1.1.计算机系统的主要部件 (1)计算机系统就是以CPU为核心来运行的系统.典型的计算机系统有:PC机(台式机+笔记本).嵌入式设备(手机.平板电脑.游戏机).单片机(家用 ...

  8. Docker学习总结(17)——学会使用Dockerfile

    Docker.Dockerfile.Docker镜像.容器这些都是什么鸟? 老生常谈,再再再--普及一下: Docker: 最早是dotCloud公司出品的一套容器管理工具,但后来Docker慢慢火起 ...

  9. Luogu P1257 平面上的最接近点对 暴力

    这道题数据不大 两点距离用勾股定理求 #include<iostream> #include<cmath> using namespace std; struct node{ ...

  10. 【BZOJ4398】福慧双修(二进制,最短路)

    题意: 此题中S=1 思路:Orz ManGod秒切此题 我觉得出入边权互换不太直观,就改了一下写法 第一次默认与1有关的第一条出边只出不入,第二次默认只入不出 ..]of longint; head ...