hdu6148 百度之星程序设计竞赛复赛 (数位dp)
Valley Numer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1402 Accepted Submission(s): 713
它最近发明了一种新的数字:Valley Number,像山谷一样的数字。

当一个数字,从左到右依次看过去数字没有出现先递增接着递减的“山峰”现象,就被称作 Valley Number。它可以递增,也可以递减,还可以先递减再递增。在递增或递减的过程中可以出现相等的情况。
比如,1,10,12,212,32122都是 Valley Number。
121,12331,21212则不是。
度度熊想知道不大于N的Valley Number数有多少。
注意,前导0是不合法的。
每组数据包含一个数N。
● 1≤T≤200
● 1≤length(N)≤100
3
14
120
14
119
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<cmath>
#include<list>
#include<deque>
#include<cstdlib>
#include<bitset>
#include<stack>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
string s;
ll a[],dp[][][];
ll dfs(int pos,int pre,int turn,bool limit,bool invalid)
{//pos为位置,turn为1表示上升,2下降,0未知,limit记录数位是否达上界,invalid记录前导是否都为0
if(pos==-) return invalid?:; //如果全部为0,不合法返回0,否则返回1
if(!limit&&dp[pos][pre][turn]!=-)
return dp[pos][pre][turn]; //被记忆过了
int up=limit?a[pos]:; //是否达上界
ll ans=;
for(int i=;i<=up;i++)
{
if(turn==&&i<pre) continue;
int x;
if(i==pre) x=turn;
else if(i>pre) x=;
else x=;
if(invalid) x=;
ans=(ans+dfs(pos-,i,x,limit&&i==a[pos],i==&&invalid))%mod;
}
if(!limit) dp[pos][pre][turn]=ans; //记忆化
return ans;
}
ll solve(string x)
{
int pos=;
for(int i=x.length()-;i>=;i--)
a[pos++]=x[i]-'';
return dfs(pos-,,,true,true);
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie();
int T;
cin>>T;
while(T--)
{
string s;
memset(dp,-,sizeof(dp));
cin>>s;
cout<<solve(s)<<endl;
}
return ;
}
hdu6148 百度之星程序设计竞赛复赛 (数位dp)的更多相关文章
- 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】
Valley Numer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- 2017"百度之星"程序设计大赛 - 复赛 01,03,05
Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】
Pokémon GO Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】
Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- [SinGuLaRiTy] 2017 百度之星程序设计大赛 复赛
[SinGuLaRiTy-1038] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. Arithmetic of Bomb Problem D ...
- 2017百度之星程序设计大赛 - 复赛 Arithmetic of Bomb
http://acm.hdu.edu.cn/showproblem.php?pid=6144 解法:一个简单的模拟 #include <bits/stdc++.h> using names ...
- 2017"百度之星"程序设计大赛 - 复赛
Arithmetic of Bomb Accepts: 1050 Submissions: 1762 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 【2017百度之星程序设计大赛 - 复赛】Valley Numer
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6148 [题意] 在这里写题意 [题解] 先把1..N里面的山峰数字个数算出来->x 然后用N减去这 ...
- 【2017"百度之星"程序设计大赛 - 复赛】Arithmetic of Bomb
[链接]http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=777&pid=1001 [题意] 在这里写 [题解] ...
随机推荐
- python中$和@基础笔记
python 2.4以后,增加了@符号修饰函数对函数进行修饰,python3.0/2.6又增加了对类的修饰. $ 在正则表达式中,匹配一个字符串的末尾.(参考http://www.runoob.com ...
- Azure系列2.1.4 —— BlobInputStream
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...
- [转帖]windows+xshell+xming访问非桌面版Linux服务器
windows+xshell+xming访问非桌面版Linux服务器 2016年06月05日 00:09:11 jxxiaohou 阅读数:11996 标签: Linux 更多 个人分类: Linux ...
- ELK日志系统+x-pack安全验证
根据之前已经搭好的ELK系统,现在加一个x-pack插件上去,不然谁拿到ip和端口都可以访问elasticsearch和kibana. 要的效果如下:打开kibana界面的时候要让其输入用户名密码才能 ...
- JavaScript charAt() 方法
<script> var str="abcdef"; alert(str[0]); //a,高版本浏览器兼容 alert(str.charAt(0)); //a,兼容所 ...
- 4.请介绍一下c++和Java的区别
1.指针 2.c++多重继承,Java只能继承一个父类,但是可以继承多个接口 3.数据类型及类,Java完全面向对象,所有函数和变量都必须是类的一部分.而c++允许将函数和变量定义为全局,Java取消 ...
- QTP自动化测试-点滴-步骤
1 添加 test 2 设置 整个测试项目的 setting -数据表位置 3 添加 引用 方法文件 4 添加 action 5 添加 action 对应的 repository 控件库 6 录制.整 ...
- python之if使用方法举例
if使用方法举例: import random #随机生成1-100的整数 n = random.randint(1, 100) if n > 50: print(n, "> 5 ...
- web跨域请求
第一种情况: 1. sina.com=====>baidu.com/xxx.jsp 也就是前面的域名不相同,(url第三根斜杠之前的内容,也就是主机) 2:localhost =====> ...
- C# WebSocket模拟发送接收
WebSocket服务端 C#示例代码 using System; using System.Collections.Generic; using System.Linq; using System. ...