HDU6148-Valley Numer
来源:互联网 发布:易税软件下载 编辑:程序博客网 时间:2024/05/22 15:23
Valley Numer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 477 Accepted Submission(s): 252
Problem Description
众所周知,度度熊非常喜欢数字。
它最近发明了一种新的数字:Valley Number,像山谷一样的数字。
当一个数字,从左到右依次看过去数字没有出现先递增接着递减的“山峰”现象,就被称作 Valley Number。它可以递增,也可以递减,还可以先递减再递增。在递增或递减的过程中可以出现相等的情况。
比如,1,10,12,212,32122都是 Valley Number。
121,12331,21212则不是。
度度熊想知道不大于N的Valley Number数有多少。
注意,前导0是不合法的。
它最近发明了一种新的数字:Valley Number,像山谷一样的数字。
当一个数字,从左到右依次看过去数字没有出现先递增接着递减的“山峰”现象,就被称作 Valley Number。它可以递增,也可以递减,还可以先递减再递增。在递增或递减的过程中可以出现相等的情况。
比如,1,10,12,212,32122都是 Valley Number。
121,12331,21212则不是。
度度熊想知道不大于N的Valley Number数有多少。
注意,前导0是不合法的。
Input
第一行为T,表示输入数据组数。
每组数据包含一个数N。
● 1≤T≤200
● 1≤length(N)≤100
每组数据包含一个数N。
● 1≤T≤200
● 1≤length(N)≤100
Output
对每组数据输出不大于N的Valley Number个数,结果对 1 000 000 007 取模。
Sample Input
3314120
Sample Output
314119
Source
2017百度之星程序设计大赛 - 复赛
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;const LL mod = 1e9 + 7;char ch[105];int a[105];LL dp[105][15][5];LL dfs(int pos, int pre, int sta, bool limit){ if (pos == -1) { if (!sta) return 0; return 1; } if (!limit&&dp[pos][pre][sta] != -1) return dp[pos][pre][sta]; int up = limit ? a[pos] : 9; LL ans = 0; for (int i = 0; i <= up; i++) { if (sta == 2 && pre <= i) (ans += dfs(pos - 1, i, sta, limit&&i == up)) %= mod; if (sta == 1) { if (pre >= i) (ans += dfs(pos - 1, i, sta, limit&&i == up)) %= mod; else (ans += dfs(pos - 1, i, 2, limit&&i == up)) %= mod; } if (sta == 0) { if (i == 0) (ans += dfs(pos - 1, i, 0, limit &&i == up)) %= mod; else (ans += dfs(pos - 1, i, 1, limit&&i == up)) %= mod; } } if (!limit) dp[pos][pre][sta] = ans; return ans;}int main(){ int t; scanf("%d", &t); while (t--) { memset(dp, -1, sizeof dp); scanf("%s", ch); int len = strlen(ch); for (int i = 0; i < len; i++) a[i] = ch[len - i - 1] - '0'; printf("%lld\n", dfs(len - 1, 0, 0, 1)); } return 0;}
阅读全文
0 0
- HDU6148-Valley Numer
- hdu6148-Valley Numer(数位dp)
- HDU6148 Valley Numer (2017百度之星程序设计大赛
- 百度之星Valley Numer
- 数位DP——HDU6148 Valley Number
- 【数位DP】HDU6148[Valley Number]题解
- hdu 6148 Valley Numer 数位dp
- HDU 6148 Valley Numer [数位dp]
- hdu 6148 Valley Numer(数位DP)
- 百度之星复赛Valley Numer II
- Hdu 6148 Valley Numer 数位DP
- hdu 6149 Valley Numer II(状压+ 枚举)
- 【HDU6149】Valley Numer II(状压DP)
- hdu 6148 Valley Numer (数位dp)
- HDU6149[Valley Numer II]--压位DP
- hdu 6148 Valley Numer (数位dp)
- HDU 6148 Valley Numer (数位dp)
- 百度之星复赛--Valley Numer----数位dp
- ubuntu14.04+ROS+KINECT V2校准
- HDU 1874 畅通工程续 【最短路入门题】
- Android Studio 快捷键汇总
- StringBuffer清空操作delete和setLength的效率对比分析
- Intellij IDEA 安装jnetpcap开发环境与 no jnetpcap in java.library.path 的解决方案
- HDU6148-Valley Numer
- Vue之Unexpected token
- Ubuntu 14.04 安装 Sublime Text 3
- Git与Svn的区别
- 读书笔记《机器学习》:第二章:模型评估与选择
- 秒杀系统的一点思考
- nefu120 梅森素数(数论)
- 数据库的读写分离
- Linux平台用C++封装线程读写锁