HDU 1176 经典dp
记录最晚时间 从time为2枚举到最晚时间 每个时间段的x轴节点都等于上一个时间段的可触及的最大馅饼数
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<math.h>
using namespace std;
int dp[100050][11];
int a[100050][11];
void init()
{
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
}
int main(){
int n;
while(~scanf("%d",&n))
{
if(n==0)
break;
init();
int q,w;
int t=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&q,&w);
a[w][q]++;
if(w>t)
t=w;
}
dp[1][4]=a[1][4];
dp[1][5]=a[1][5];
dp[1][6]=a[1][6];
for(int i=2;i<=t;i++)
{
dp[i][0]=max(dp[i-1][0]+a[i][0],dp[i-1][1]+a[i][0]);
dp[i][10]=max(dp[i-1][10]+a[i][10],dp[i-1][9]+a[i][10]);
for(int k=1;k<=9;k++)
{
dp[i][k]=max(max(dp[i-1][k-1],dp[i-1][k]),dp[i-1][k+1])+a[i][k];
}
}
int ans=0;
for(int i=0;i<=10;i++)
{
if(dp[t][i]>ans)
ans=dp[t][i];
}
printf("%d\n",ans);
}
}
HDU 1176 经典dp的更多相关文章
- hdu 1421经典dp
#include<stdio.h> #include<stdlib.h> #define N 2001 #define inf 0x3fffffff int a[N],dp[N ...
- 免费馅饼 HDU - 1176 基础dp
/*题都是有一个状态转移方程式 , 只要推出方程式就问题不大了,首 先对于gameboy来说他下一秒只能 在0~10这十一个位置移动, 而对于1~9这九个位置来说他可以移动(假设他现在的位置为x)到x ...
- 【DP】HDU 1176
HDU 1176 免费馅饼 题意:中文题目不解释. 思路:因为是从中间出发所以思路卡了许久,还在之前做了道HIHO入门的题.能想到的点,从时间思考,然后初始化1s的时候,4,5,6,的数值要特别赋值. ...
- HDU 1176免费馅饼 DP数塔问题转化
L - 免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- 怒刷DP之 HDU 1176
免费馅饼 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- HDU 1176 免费馅饼(DP)
职务地址:HDU 1176 以时间为横轴.11个点位纵轴构造一个矩阵.然后利用数字三角形的方法从上往下递推下去. 代码例如以下: #include <iostream> #include ...
- HDU 1176 免费馅饼(记忆化搜索)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
随机推荐
- linux网络编程_1
本文属于转载,稍有改动,以利于学习. (一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个 ...
- Fresco 源码分析(三) Fresco服务端处理(2) Producer具体实现的内容
我们以mProducerFactory.newNetworkFetchProducer()为例,因为这些创建新的producer的方式类似,区别在于是否有包装的处理器,即如果当前处理器中没有正在处理的 ...
- TinyHttpd中sockaddr与struct sockaddr_in的区别
上午学习TinyHttpd的源码,sockaddr 结构体以前没接触过, 在网络编程中经常用到struct sockaddr和struct sockaddr_in,这里简单介绍. 在linux环境下, ...
- ubuntu下打开终端插件
一个 nautilus 插件,用于在任意目录中打开终端 nautilus-open-terminal
- android 拨号
public class CallActivity extends Activity { @Override public void onCreate(Bundle savedInstanceStat ...
- java实例--海盗的最优方案
package unit4; public class Pirate{ private String name; private int[] schemes; private int index; p ...
- Fibonacci Again
Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) ...
- Codeforces Round #330 (Div. 2)
C题题目出错了,unrating,2题就能有很好的名次,只能呵呵了. 水 A - Vitaly and Night /***************************************** ...
- 位运算 2013年山东省赛 F Alice and Bob
题目传送门 /* 题意: 求(a0*x^(2^0)+1) * (a1 * x^(2^1)+1)*.......*(an-1 * x^(2^(n-1))+1) 式子中,x的p次方的系数 二进制位运算:p ...
- ZOJ1655 Transport Goods(Floyd)
利用Floyd的DP状态转移方程. #include<cstdio> #include<cstring> #include<queue> #include<a ...