[数字dp] hdu 3565 Bi-peak Number
意甲冠军:
为了范围[X,Y],的最大位数的范围内的需求高峰和值多少。
双峰是为了满足一些规定数量 你可以切两 /\ /\ 形式。
思维:
dp[site][cur][ok] site地点 面的数是cur 状态为ok
ok分为7种
0:前面全部数都是0
1:第一个峰数且仅仅有一个数
2:第一个峰数在峰顶(可上可下)
3:第一个峰数在峰底(可进入下一个峰或者继续往下)
4:同1 是第二个峰数
5:同2 是第二个峰数
6:同3 可是不可进入下一个峰数了
代码:
#include"cstdlib"
#include"cstdio"
#include"cstring"
#include"cmath"
#include"queue"
#include"algorithm"
#include"iostream"
using namespace std;
#define ll unsigned __int64
int dp[30][10][7];
int numx[30],numy[30];
int dfs(int site,int cur,int ok,int fa,int fb) //由于是大小 所以要在中间推断
{
if(site==0) return ok==6?0:-1; //状态6代表成立的数
if(!fa&&!fb&&~dp[site][cur][ok]) return dp[site][cur][ok]; //都不是边界
int Min=fa? numx[site]:0; //上界
int Max=fb?numy[site]:9; //下界
int ans=-1; //初值
for(int i=Min; i<=Max; i++)
{
int tep=0;
if(ok==0&&i) tep=1; //去前导0
else if(ok==1)
{
if(i>cur) tep=2; //往上走
else tep=-1; //无法走
}
else if(ok==2)
{
if(i>cur) tep=2; //继续上
else if(i==cur) tep=-1; //相等不能走
else tep=3; //往下
}
else if(ok==3)
{
if(i>cur) tep=4; //跳到第二个峰
else if(i==cur) //相等的话0不能跳,由于不能前导0
{
if(i) tep=4;
else tep=-1;
}
else tep=3; //继续下
}
else if(ok==4) //下同上
{
if(i>cur) tep=5;
else tep=-1;
}
else if(ok==5)
{
if(i>cur) tep=5;
else if(i==cur) tep=-1;
else tep=6;
}
else if(ok==6)
{
if(i>=cur) tep=-1; //最后仅仅能下不能跳了
else tep=6;
}
if(tep!=-1)
{
int sum=dfs(site-1,i,tep,fa&&i==Min,fb&&i==Max); //这位放完 后面的最大值
if(sum!=-1) ans=max(ans,sum+i); //加上这位比大小
}
}
if(!fa&&!fb) dp[site][cur][ok]=ans; //不是边界保存值
return ans;
}
int main()
{
int t,cas=1;
cin>>t;
memset(dp,-1,sizeof(dp));
while(t--)
{
ll x,y;
scanf("%I64u%I64u",&x,&y); //注意2^64次方 要用无符号64位读入
int cnt=0;
while(y)
{
cnt++;
numx[cnt]=x%10;
x/=10;
numy[cnt]=y%10;
y/=10;
}
int ans=dfs(cnt,0,0,1,1);
printf("Case %d: %d\n",cas++,ans==-1?0:ans);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
[数字dp] hdu 3565 Bi-peak Number的更多相关文章
- [数字dp] hdu 3271 SNIBB
意甲冠军:有两个查询: q=1.在[x,y]间隔,兑换b十进制,数字和m多少个月. q=2.在[x,y]间隔,兑换b十进制,数字是m第一k的数目是多少(十进制),没有输出由给定的主题. 思维: 和比特 ...
- HDU - 4734 F(x) (2013成都网络游戏,数字DP)
意甲冠军:求0-B见面<=F[A]所有可能的 思维:数字DP,内存搜索 #include <iostream> #include <cstring> #include & ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- 动手写个数字输入框1:input[type=number]的遗憾
前言 最近在用Polymer封装纯数字的输入框,开发过程中发现不少坑,也有很多值得研究的地方.本系列打算分4篇来叙述这段可歌可泣的踩坑经历: <动手写个数字输入框1:input[type=nu ...
- hdu 6216 A Cubic number and A Cubic Number【数学题】
hdu 6216 A Cubic number and A Cubic Number[数学] 题意:判断一个素数是否是两个立方数之差,就是验差分.. 题解:只有相邻两立方数之差才可能,,因为x^3-y ...
- HDU 1394 Minimum Inversion Number(线段树求最小逆序数对)
HDU 1394 Minimum Inversion Number(线段树求最小逆序数对) ACM 题目地址:HDU 1394 Minimum Inversion Number 题意: 给一个序列由 ...
- HDU 6093 - Rikka with Number | 2017 Multi-University Training Contest 5
JAVA+大数搞了一遍- - 不是很麻烦- - /* HDU 6093 - Rikka with Number [ 进制转换,康托展开,大数 ] | 2017 Multi-University Tra ...
- fwt优化+树形DP HDU 5909
//fwt优化+树形DP HDU 5909 //见官方题解 // BestCoder Round #88 http://bestcoder.hdu.edu.cn/ #include <bits/ ...
- HDU 3565 Bi-peak Number(数位DP)题解
题意:我们定义每一位先严格递增(第一位不为0)后严格递减的数为峰(比如1231),一个数由两个峰组成称为双峰,一个双峰的价值为每一位位数和,问L~R双峰最大价值 思路:数位DP.显然这个问题和pos有 ...
随机推荐
- 也说Javascript对象拷贝及疑问
一.浅拷贝 当我们需要将一个对象拷贝至另一个对象时,我们一般会这么实现 function shadowCopy(source,target){ var target=target||{}; for(v ...
- HUNNU11352:Digit Solitaire
Problem description Despite the glorious fall colors in the midwest, there is a great deal of time t ...
- POJ 3181 Dollar Dayz 简单DP
这DP虽然简单 但是思考一下还是挺好的 题意是 1,2,3,4....k 用加法凑成N 每个数可取不限个数 令dp[i][j] 表示前i种数凑成j的方案数 然后dp[i][j] = dp[i - 1] ...
- Codeforces Round#310 div2
C题:这题说的是套娃,如果做题的时候知道是套娃,那就好理解多了 规则1:套娃A可以放到套娃B里面,当且仅当套娃B没有放在其他套娃里面 规则2:套娃A放在套娃B里面,且套娃B没有放在其他套娃里面,那么可 ...
- POJ 1287 Networking(最小生成树)
题意 给你n个点 m条边 求最小生成树的权 这是最裸的最小生成树了 #include<cstdio> #include<cstring> #include<algor ...
- ASP.NET 应用程序生命周期
1.请求到达IIS服务器,IIS根据文件后缀找到对应的ISAPI(Internet Server API)扩展来处理,这个配置可在网站属性里的“根目录”选项卡中的“配置”里看到.可以看到,ashx.a ...
- 【JUnit4.10来源分析】0导航
JUnit靠GOF 中的一个Erich Gamma和 Kent Beck 单元测试框架编写一个开源,yqj2065分析JUnit的主要目的是源 中学习对设计模式的运用. JUnit也是一个学习Java ...
- android学习一些帖子
关于谷歌和苹果的帖子 http://news.eoe.cn/18576.html android无线调试的帖子: http://baoyz.com/android/2014/06/24/adb-wir ...
- Ios 该图显示其出现的相关问题定义UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
解决这个问题 在 加上个 标示符 Cell 自己定义 customCell .h 代码例如以下 ViewController.m 文件里 代码例如以下 执行结果 吕 图坚持直接在这里 不行
- uva 11992 为矩阵更新查询段树
http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&page=show_problem& ...