UESTC_邱老师选妹子 2015 UESTC Training for Dynamic Programming<Problem H>
H - 邱老师选妹子
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
邱老师长得帅这是人尽皆知,于是追他的妹子就会很多。
但是你知道,邱老师是一个很专一的人,所以他心里面只能有一个人。
于是他决定从追他的众多妹子里挑选一个出来。于是酱神给邱老师出来一个主意,已知有一些妹子,恰好可以给她们从l到r排号,使得每一个妹子有单独的数字,而正好有r-l+1个妹子。
酱神说,我们不能要运气不好的女孩,而酱神又给了两个数字62和4,如果妹子的排号里面有62(必须是连续的)或4,那么就排除他现在给你l和r,问有多少妹子可以有幸在第一轮留下。
Input
输入的都是整数对l、r(0<l≤r<1000000),如果遇到都是0的整数对,则输入结束。
Output
每组数据输出占一行,对于每个l和r 输出有多少个妹子可以在第一轮不被排除
Sample input and output
| Sample Input | Sample Output |
|---|---|
1 100 |
80 |
Hint
不好的数字为所有含有4或62的号码。例如:
62315 73418 88914
都属于不好的。但是,61152虽然含有6和2,但不是62连号
解题报告:
我们考虑f( a , b , c , d , e) -> 正在转移第 a 位,且前一位是 b ,c 表示是否小于过上界, d 表示是否大于过下界 , e 表示目前的状态 的合法方案数.
转移时通过 c 和 d来确定枚举的上下界,同时注意上一位数和status进行枚举和转移.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
typedef long long ll;
using namespace std;
ll f[][][][][];
string A,B;
int len; ll dfs(int cur,int front,int f1,int f2,int status)
{
if (f[cur][front][f1][f2][status] != -)
return f[cur][front][f1][f2][status];
ll & ans = f[cur][front][f1][f2][status] = ;
if (cur == len)
return ans = status;
int st = f1 ? : A[cur]-'';
int ed = f2 ? : B[cur]-'';
for(int i = st ; i <= ed ; ++ i)
{
if (i == )
ans += dfs(cur+,i,f1 | i > A[cur]-'' , f2 | i < B[cur] - '',);
else if (i == )
{
if (front == )
ans += dfs(cur+,i,f1 | i > A[cur]-'' , f2 | i < B[cur] - '',);
else
ans += dfs(cur+,i,f1 | i > A[cur]-'' , f2 | i < B[cur] - '',status);
}
else
ans += dfs(cur+,i,f1 | i > A[cur]-'' , f2 | i < B[cur] - '',status);
}
return ans;
} int main(int argc,char *argv[])
{
ios::sync_with_stdio(false);
while(cin >> A >> B)
{
if (A[] == '' && B[] == '')
break;
memset(f,-,sizeof(f));
len = B.size();
while(A.size() != B.size()) // Init;
A = '' + A;
cout << dfs(,,,,) << endl;
}
return ;
}
UESTC_邱老师选妹子 2015 UESTC Training for Dynamic Programming<Problem H>的更多相关文章
- UESTC_邱老师看电影 2015 UESTC Training for Dynamic Programming<Problem F>
F - 邱老师看电影 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_邱老师玩游戏 2015 UESTC Training for Dynamic Programming<Problem G>
G - 邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submi ...
- UESTC_邱老师的脑残粉 2015 UESTC Training for Graph Theory<Problem D>
D - 邱老师的脑残粉 Time Limit: 12000/4000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Sub ...
- UESTC_酱神的旅行 2015 UESTC Training for Dynamic Programming<Problem M>
M - 酱神的旅行 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- UESTC_男神的约会 2015 UESTC Training for Dynamic Programming<Problem J>
J - 男神的约会 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- UESTC_酱神赏花 2015 UESTC Training for Dynamic Programming<Problem C>
C - 酱神赏花 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 262143/262143KB (Java/Others) Submi ...
- UESTC_男神的礼物 2015 UESTC Training for Dynamic Programming<Problem A>
A - 男神的礼物 Time Limit: 3000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- UESTC_邱老师选妹子(二) 2015 UESTC Training for Dynamic Programming<Problem I>
I - 邱老师选妹子(二) Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Su ...
- UESTC_邱老师降临小行星 2015 UESTC Training for Search Algorithm & String<Problem B>
B - 邱老师降临小行星 Time Limit: 10000/5000MS (Java/Others) Memory Limit: 65536/65535KB (Java/Others) Su ...
随机推荐
- 【转】 树莓派学习笔记——I2C设备载入和速率设置
原文网址:http://blog.csdn.net/xukai871105/article/details/18234075 1.载入设备 方法1——临时载入设备 sudo modprobe -r i ...
- Android_Studio 及SDK下载
Android Studio includes all the tools you need to build apps for Android. DOWNLOAD ANDROID STUDIO 2. ...
- WEB打印插件Lodop
Lodop.C-Lodop使用说明及样例 Lodop(标音:劳道谱,俗称:露肚皮)是专业WEB控件,用它既可裁剪输出页面内容,又可用程序代码直接实现 复杂打印.控件功能强大,却简单易用,所有调用如 ...
- poj 3262 Protecting the Flowers 贪心
题意:给定n个奶牛,FJ把奶牛i从其位置送回牛棚并回到草坪要花费2*t[i]时间,同时留在草地上的奶牛j每分钟会消耗d[j]个草 求把所有奶牛送回牛棚内,所消耗草的最小值 思路:贪心,假设奶牛a和奶牛 ...
- JAVA中的正则表达式--待续
1.关于“\”,在JAVA中的正则表达式中的不同: 在其他语言中"\\"表示为:我想要在正则表达式中插入一个普通的反斜杠: 在Java中“\\”表示为:我想要插入一个正则表达式反斜 ...
- PHP商城购物车类
<?php /* 购物车类 */ // session_start(); class Cart { //定义一个数组来保存购物车商品 private $iteams; private stati ...
- handsontable的核心方法
1.为handsontable添加钩子方法 addHook(key,callback):key为钩子方法名 <span style="font-size:18px;"> ...
- UITextField输入长度限制
[_yourTextField addTarget:self action:@selector(eventEditingChange:) forControlEvents:UIControlEvent ...
- Hibernate(二)——POJO对象的操作
POJO对象其实就是我们的实体,这篇博客总结一下框架对POJO对象对应数据库主键的生成策略,和一些对POJO对象的简单增删改查的操作. 一,Hibernate框架中主键的生成策略有三种方式: 1,数 ...
- 【Struts2】新建一个Struts2工程,初步体验MVC
实现目标 地址栏输入http://localhost:88/Struts2HelloWorld/helloworld.jsp 输入用户名,交由http://localhost:88/Struts2He ...