hdu 3886 Final Kichiku “Lanlanshu” 数位DP
思路:
dp[i][j][k]:满足在字符串的j位,前一位数字是k。
代码如下:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define M 100000000
using namespace std;
char str[],a[],b[];
int len,bit[],dp[][][];
bool ok(int i,int u,int v)
{
if(str[i]=='/') return u<v;
if(str[i]=='-') return u==v;
if(str[i]=='\\') return u>v;
}
int dfs(int pos,int j,int pre,bool h,bool f)
{
if(pos==-) return j==len;
if(!f&&dp[pos][j][pre]!=-) return dp[pos][j][pre];
int ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
if(h) ans+=dfs(pos-,j,i,h&&i==,f&&i==e);
else if(j<len&&ok(j,pre,i)) ans+=dfs(pos-,j+,i,h,f&&i==e);
else if(j>&&ok(j-,pre,i)) ans+=dfs(pos-,j,i,h,f&&i==e);
ans%=M;
}
if(!f) dp[pos][j][pre]=ans;
return ans;
}
int solve(char an[],bool f)
{
int m=,i,j=,le=strlen(an);
while(an[j]=='') j++;
for(i=le-;i>=j;i--) bit[m++]=an[i]-'';
if(f&&m>){
for(i=;i<m;i++){
if(bit[i]){
bit[i]--;
break;
}
else bit[i]=;
}
}
return dfs(m-,,,,);
}
int main()
{
int i,j,k,m,n;
while(scanf("%s",str)!=EOF){
len=strlen(str);
scanf("%s%s",a,b);
memset(dp,-,sizeof(dp));
printf("%08d\n",(solve(b,)-solve(a,)+M)%M);
}
return ;
}
hdu 3886 Final Kichiku “Lanlanshu” 数位DP的更多相关文章
- hdu_3886_Final Kichiku “Lanlanshu”(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3886 题意:这题的题意有点晦涩难懂,大概意思就是给你一个区间,让你找一些满足递增递减条件的数,举个列: ...
- hdu 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- HDU 4507 (鬼畜级别的数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4507 题目大意:求指定范围内与7不沾边的所有数的平方和.结果要mod 10^9+7(鬼畜の元凶) 解题 ...
- HDU 5787 K-wolf Number (数位DP)
K-wolf Number 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5787 Description Alice thinks an integ ...
- 【HDOJ】3386 Final Kichiku “Lanlanshu”
数位DP.需要注意的是需要特殊处理前导0,另外连续的==匹配,不要计重了,尽量贪心的匹配掉. /* 3886 */ #include <iostream> #include <sst ...
- 【HDU 3652】 B-number (数位DP)
B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose de ...
- HDU 5787 K-wolf Number(数位DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5787 [题目大意] 求区间[L,R]内十进制数相邻k位之间不相同的数字的个数. [题解] 很显然的 ...
- 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 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
随机推荐
- Android中修改状态栏的颜色和我们App的风格一致
其实也没什么东西,就是一个主题,下面看代码: <resources> <!-- Base application theme. --> <style name=" ...
- Android线程---UI线程和非UI线程之间通信
近期自学到了线程这一块,用了一上午的时间终于搞出来了主.子线程间的相互通信.当主线程sendMessage后,子线程便会调用handleMessage来获取你所发送的Message.我的主线程 ...
- hdu 4324 Triangle LOVE
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...
- ios中怎么样自动剪切图片周围超出的部分
UIImageView *image = [[UIImageView alloc] init]; image.clipsToBounds = YES;
- MVC4.0 利用IActionFilter实现简单的后台操作日志功能
首先我们要了解MVC提供了4种常用的拦截器:IActionFilter(Action拦截器接口).IExceptionFilter(异常拦截器接口).IResultFilter(Result拦截器接口 ...
- ifstat-网络接口监测工具
ifstat-网络接口监测工具 http://gael.roualland.free.fr/ifstat/ ifstat is a tool to report network interfaces ...
- C#全局作用符::
比如说你在全局定义了一个变量str,然后在函数里面又定义了这个str名字的变量的,这个时候你要是在函数里面直接写str,那么就是访问的函数内部的变量的.无法访问外部变量的.这是正常的现象的.但是如果你 ...
- < java.util >-- List接口
List本身是Collection接口的子接口,具备了Collection的所有方法.现在学习List体系特有的共性方法,查阅方法发现List的特有方法都有索引,这是该集合最大的特点. List:有序 ...
- tcp传输黏包
tcp传输黏包 tcpip协议使用"流式"(套接字)进行数据的传输,就是说它保证数据的可达以及数据抵达的顺序,但并不保证数据是否在你接收的时候就到达,特别是为了提高效率,充分利用带 ...
- Android编程小实验
1.一个layout中存在相同id的控件会出现什么情况? 结论:编译和运行的时候都不会报错,不过使用findViewById()只会获取第一个该id的控件 来自为知笔记(Wiz)