hdu_3565_Bi-peak Number(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3565
题意:给你一个区间,让你找这个区间内有两个山峰的数的最大和,什么是两个山峰,比如121121 第一个2 和第二个2就是两个峰
题解:求的这个不满足dfs(y)-dfs(x)所以只有用一个上限和一个下限来限制
s=0:前导0的状态;
s=1:第一个山峰的上坡,且不能立马下坡;
s=2:第一个山峰的上坡,且最后一点能看成是最高点,下一个点可以是下坡;
s=3:第一个山峰的下坡;
s=4:第二个山峰的上坡,且不能立马下坡;
s=5:第二个山峰的上坡,且最后一点能看成是最高点,下一个点可以是下坡;
s=6:第二个山峰的下坡;
s=-1:其余不合法的状态。
设dp[i][j][k]为考虑第i位,上一个数字为j,状态s为k的最大数位和
#include<cstdio>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define F(i,a,b) for(int i=a;i<=b;i++) int dp[][][],ss[],ee[],t,len,an;unsigned __int64 x,y; int dfs(int pos,int pre,int s,int fx,int fy){
if(!pos)return s==?:-;
if(!fx&&!fy&&dp[pos][pre][s]!=-)return dp[pos][pre][s];
int st=fx?ss[pos]:,end=fy?ee[pos]:,ans=-,tp,ns;
F(i,st,end){
ns=s;
if(!s&&i)ns=;
else if(s==){if(i>pre)ns=;else ns=-;}
else if(s==){if(i<pre)ns=;else if(i==pre)ns=-;}
else if(s==&&i>=pre){if(i)ns=;else ns=-;}
else if(s==){if(i>pre)ns=;else ns=-;}
else if(s==){if(i<pre)ns=;else if(i==pre)ns=-;}
else if(s==&&i>=pre)ns=-;
if(ns!=-)tp=dfs(pos-,i,ns,fx&&i==st,fy&&i==end),ans=(tp==-?ans:MAX(ans,i+tp));
}
if(!fx&&!fy)dp[pos][pre][s]=ans;
return ans;
} int main(){
F(i,,)F(j,,)F(k,,)dp[i][j][k]=-;
scanf("%d",&t);
F(i,,t){
scanf("%I64u%I64u",&x,&y);
for(len=;y;x/=,y/=)ss[++len]=x%,ee[len]=y%;
an=dfs(len,,,,),printf("Case %d: %d\n",i,an==-?:an);
}
return ;
}
hdu_3565_Bi-peak Number(数位DP)的更多相关文章
- 多校5 HDU5787 K-wolf Number 数位DP
// 多校5 HDU5787 K-wolf Number 数位DP // dp[pos][a][b][c][d][f] 当前在pos,前四个数分别是a b c d // f 用作标记,当现在枚举的数小 ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- HDU 5787 K-wolf Number 数位DP
K-wolf Number Problem Description Alice thinks an integer x is a K-wolf number, if every K adjacen ...
- Fzu2109 Mountain Number 数位dp
Accept: 189 Submit: 461Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description One ...
- HDU 3709 Balanced Number (数位DP)
Balanced Number Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) ...
- beautiful number 数位DP codeforces 55D
题目链接: http://codeforces.com/problemset/problem/55/D 数位DP 题目描述: 一个数能被它每位上的数字整除(0除外),那么它就是beautiful nu ...
- FZU - 2109 Mountain Number 数位dp
Mountain Number One integer number x is called "Mountain Number" if: (1) x>0 and x is a ...
- BNU 13024 . Fi Binary Number 数位dp/fibonacci数列
B. Fi Binary Number A Fi-binary number is a number that contains only 0 and 1. It does not conta ...
- hdu 5898 odd-even number(数位dp)
Problem Description For a number,if the length of continuous odd digits is even and the length of co ...
随机推荐
- C++中int转为char 以及int 转为string和string 转int和空格分隔字符串
1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...
- SpringMVC之ModelAndView的简单使用
可以使用ModelAndView来跳转页面和传值,具体用法如下: 构造方法的参数是要跳转的页面! 通过 ModelAndView 的对象的 AddObject(K,V)方法,可以传入数据! 获得mod ...
- 未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage“提示信息
在安装过vs2015之后出现未能正确加载“Microsoft.VisualStudio.Editor.Implementation.EditorPackage“提示信息在VS的安装目录下,找到 ...
- White space is required before the encoding pseudo attribute in the XML declaration.
错误出现的位置: <?xml version="1.0"encoding="UTF-8"?> 正确方式: <?xml version=&quo ...
- day23 框架之基础加强
day23 框架之基础加强 今日任务 aptana(javascript的eclipse插件):http://www.cnblogs.com/terrylin/archive/2012/06/20/2 ...
- Linux服务器导入导出SVN项目
导出项目: # svnadmin dump /var/svn/pro1 > /mydata/pro1.backup 导入项目: 新建项目仓库: # svnadmin create /var/sv ...
- CodeForces 699A Launch of Collider
枚举相邻两个$a[i]$与$a[i+1]$,如果$s[i]=R$并且$s[i+1]=L$,那么$i$和$i+1$会碰撞,更新答案. #pragma comment(linker, "/STA ...
- java 邮件发送 apache commons-email
package com.sun.mail;import org.apache.commons.mail.Email;import org.apache.commons.mail.EmailExcept ...
- java中的foreach输出数组中的元素
public class forEach { public static void main(String[]args){ String [] hobby = {"imooc",& ...
- HTTP运行时与页面执行模型
注:本文为个人学习摘录,原文地址:http://www.cnblogs.com/stwyhm/archive/2006/08/09/471765.html HTTP运行时 HTTP运行期处理客户端应用 ...