HDU 6148 Valley Numer (数位DP)
题意:。。。
析:好久没写数位DP了,几乎就是不会了。。。。
dp[i][last][s] 表示前 i 位上一位是 last,当前的状态是 s,0表示非上升,1 表示非下降,然后就很简单了,只有 0 能转成 1,1就是最后的状态。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e16;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 10;
const LL mod = 1000000007;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r > 0 && r <= n && c > 0 && c <= m;
} LL dp[maxn][11][2];
char s[maxn];
int a[maxn]; LL dfs(int pos, int last, int s, bool is, bool ok){
if(!pos) return !is;
LL &ans = dp[pos][last][s];
if(!is && !ok && ans >= 0) return ans; int n = ok ? a[pos] : 9;
LL res = 0;
if(last == 10){
res += dfs(pos-1, 10, s, 1, ok && 0 == n);
for(int i = 1; i <= n; ++i)
res += dfs(pos-1, i, 0, 0, i == n && ok);
}
else if(s){
for(int i = last; i <= n; ++i)
res += dfs(pos-1, i, s, i == 0 && is, ok && i == n);
}
else{
for(int i = 0; i <= n; ++i)
if(i > last) res += dfs(pos-1, i, 1, is && i == 0, ok && i == n);
else res += dfs(pos-1, i, 0, is && i == 0, ok && i == n);
}
res %= mod;
if(!is && !ok) ans = res;
return res;
} LL solve(char *s){
int len = 0;
n = strlen(s);
for(int i = n-1; i >= 0; --i)
a[++len] = s[i] - '0';
return dfs(len, 10, 0, 1, 1);
} int main(){
ms(dp, -1);
int T; cin >> T;
while(T--){
scanf("%s", s);
printf("%I64d\n", solve(s));
}
return 0;
}
HDU 6148 Valley Numer (数位DP)的更多相关文章
- 【HDU】6148 Valley Numer 数位DP
[算法]数位DP [题意]定义V-number为从左到看单位数字未出现先递增后递减现象的数字,求0~N中满足条件的数字个数.T<=200,lenth(n)<=100 [题解]百度之星201 ...
- 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】
Valley Numer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 6148 Valley Numer (数位DP)题解
思路: 只要把status那里写清楚就没什么难度T^T,当然还要考虑前导零! 代码: #include<cstdio> #include<cstring> #include&l ...
- HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛
普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- HDU 2089 - 不要62 - [数位DP][入门题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 Time Limit: 1000/1000 MS (Java/Others) Memory Li ...
- HDU 5179 beautiful number 数位dp
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5179 bc(中文): http://bestcoder.hdu.edu.cn/contes ...
- [hdu 2089] 不要62 数位dp|dfs 入门
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意:求[n, m]区间内不含4和62的数字个数. 这题有两种思路,直接数位dp和dfs 数位d ...
随机推荐
- python复习之路-Day01
数据类型初识 1.数字 2 是一个整数的例子.长整数 不过是大一些的整数.3.23和52.3E-4是浮点数的例子.E标记表示10的幂.在这里,52.3E-4表示52.3 * 10-4.(-5+4j)和 ...
- golang的吐槽
烂到极致的包管理:简单清晰的包管理机制是任何一门语言都需要具备的.后起之秀的golang,在众多成熟的其他语言包管理方式,居然做成这样,简直人间地狱.
- vscode新版1.31.1使用代码检查工具ESlint支持VUE
1.VSCODE中安装ESlint省略 2.菜单文件->首选项->设置->扩展->ESLint 打钩:Eslint:Auto Fix On Save 点击此链接:在settin ...
- JAVA for循环语句的循环变量类型问题
class HalfDollars { public static void main(String [] arguments) { int[] denver = {1_900_000,1_700_0 ...
- Ceph添加/删除Mon(ceph.conf)
操作环境 ceph 0.87.7 Openstack liberty ubuntu 14.04 当前ceph配置文件如下 [global]fsid = c010eb34-ccc6-458d-9a03- ...
- Nginx not running with no error message
Nginx not running with no error message #!/bin/shecho "start"rm /etc/nginx/sites-enabled/d ...
- CCNode作为容器实现显示区域剪裁
一直把ccnode当做ui元素的容器使用,比如一段带下划线的文字,我会在一个ccnode中加入一个label和一个sprite,然后作为一个整体传出. 在主界面聊天的时候遇到一个问题,一段聊天信息需要 ...
- JavaScript知识总结--对象的相关概念
一.定义 无序属性的集合. 说白了就是一个容器,可以容纳[基本值.对象或者函数],这些东西都叫做属性.每个属性都有一个名字,每个名字都映射一个值(可以是基本类型的值,也可以是引用类型的值).从以上描述 ...
- Spring实战之通过XML装配bean
尽管Spring长期以来确实与XML有着关联,但现在需要明确的是,XML不再是配置Spring的唯一可选方案.Spring现在有了强大的自动化配置和基于Java的配置,XML不应该再是你的第一选择了. ...
- FTP服务器(SOCKET)返回异常 500 Command not understood
出现着这样的问题,一般是NLST中的参数包含特殊字符,如"\n",所以在发送SOCKET命令时,一定要检查命令参数的合法性.