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 [题意] 在这里写 [题解] ...
随机推荐
- Azure系列2.1.4 —— BlobInputStream
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...
- 994.Contiguous Array 邻近数组
描述 Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and ...
- picker-view 组件 的value失效问题
首先检查是不是漏了绑定关系 组件内 组件引用 如过还不行就用下面的方法,顺序问题 在给暂时列表赋值之后再对value赋值
- MyBatis映射文件2(不支持自增的数据库解决方案/参数处理[单参、多参、命名参数])
针对Oracle不支持自增的解决方案 Oracle不支持自增,但是它使用序列来模拟自增,每次插入数据的主键是从序列中拿到的值,那么如何获取这个值呢? <insert id="addEm ...
- python之路--subprocess,粘包现象与解决办法,缓冲区
一. subprocess 的简单用法 import subprocess sub_obj = subprocess.Popen( 'dir', #系统指令 shell=True, #固定方法 std ...
- WorldCount代码检查与优化——软件测试第三次作业
合作者:201631062222,201631062232 代码地址:https://gitee.com/biubiubiuLYQ/ceshi_secend 本次作业链接地址:https://edu. ...
- 收藏一个带动画效果的ScrollViewer以及ScrollBar的模板
这里介绍一个带动画效果的ScrollViewer和ScrollBar,总共分为两个资源字典,直接拿来引用即可: 1 ScrollBarStyle.xaml <ResourceDictionary ...
- 从主机A得到id_rsa.pub文件,在主机B创建用户danny加入该文件,实现主机A免密登录主机B
操作步骤: 1.主机A 生成公钥id_rsa.pub文件并导出该文件 root@mytest:~# ssh-keygen Generating public/private rsa key pair. ...
- ASP.NET Web API Basic Identity 中的基本身份验证
缺点 用户凭证在请求中发送. 凭据作为明文发送. 每个请求都会发送凭据. 无法注销,除非结束浏览器会话. 易于跨站点请求伪造(CSRF); 需要反CSRF措施. 优点 互联网标准. 受所有主要浏览器支 ...
- POJ 3264-Balanced Lineup-RMQ问题
裸RMQ问题 #include <cstdio> #include <algorithm> #include <cstring> using namespace s ...