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 [题意] 在这里写 [题解] ...
随机推荐
- java类库
Java的应用程序接口(API)以包的形式来组织,每个包提供大量的相关类.接口和异常处理类,这些包的集合就是Java的类库. Java类库可以分为两种 包名以java开始的包是Java核心包(Java ...
- [转帖]system()、exec()、fork()三个与进程有关的函数的比较
system().exec().fork()三个与进程有关的函数的比较 https://www.cnblogs.com/qingergege/p/6601807.html 启动新进程(system函数 ...
- TextView不用ScrollViewe也可以滚动的方法
转自:http://www.jb51.net/article/43377.htm android TextView不用ScrollViewe也可以滚动的方法. TextView textview = ...
- HashMap、HashTable、ConcurrentHashMap、HashSet区别 线程安全类
HashMap专题:HashMap的实现原理--链表散列 HashTable专题:Hashtable数据存储结构-遍历规则,Hash类型的复杂度为啥都是O(1)-源码分析 Hash,Tree数据结构时 ...
- mybatis generator的maven插件,找不到properties的配置文件错误的解决
第一次运行的时候,maven插件是正确运行了的 但后面对 maven 的 build节点做了一点修改,就开始报错,找不到 properties标签指定的的数据库连接配置文件了 修改部分如下: 这个操作 ...
- qtp 自动化测试桌面程序-点滴1(录制设置、共用文件)
1 automation-record and run settings--设置录制程序 2 将function/repository 放于单独于test的文件夹中-方便多个test使用同一个仓库.函 ...
- 关于事务回滚,rollback tran到底要不要写?
关于事务回滚,有些不明白,不知道rollback tran在什么时候用. begin tran update 表1 update 表2 commit tran 这种写法,在更新表1或表2时出错,事务会 ...
- Ubuntu16.04 启动纯文本界面方法
问题: Ubuntu16.04 如何启动纯文本界面. 解决方法: 1.系统启动后,在登陆界面点击Ctrl+Shift+F1切换到文本登陆界面: 2.修改为默认从文本界面登陆: sudo vi /etc ...
- 四、K8S
一.查看日志 journalctl -xeu kubelet
- asp.net core mvc ajaxform submit files
<form id="form1" method="post" enctype="multipart/form-data" asp-co ...