http://acm.hdu.edu.cn/showproblem.php?pid=2089

题意:求区间内满足以下条件的数量

1、数位不能出现4,2、任意两相邻数位不能是62。

解法:数位dp【pos】【sta】表示第pos位为6和不是6两种状态的满足条件的数量。

//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <ctype.h>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 10
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int a[10];
int dp[10][2]; int dfs(int pos , int pre , int sta , int limit)
{
if(pos == -1) return 1;
if(!limit && dp[pos][sta] != -1) return dp[pos][sta];
int up = limit ? a[pos] : 9 ;
int ans = 0 ;
for(int i = 0 ; i <= up ; i++)
{
if(i == 4) continue ;
if(pre == 6 && i == 2) continue ;
ans += dfs(pos-1 , i , i == 6 , limit && a[pos] == i);
}
if(!limit) dp[pos][sta] = ans ;
return ans ;
} int solve(int x)
{
int pos = 0 ;
while(x)
{
a[pos++] = x % 10 ;
x /= 10 ;
}
return dfs(pos-1 , 0 , 0 , 1);
} int main()
{ int n , m ;
memset(dp , -1 , sizeof(dp));
while(~scanf("%d%d" , &n , &m)&&n+m)
{
printf("%d\n" , solve(m) - solve(n-1));
} return 0;
}

2、暴力

//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 998244353
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int a[10];
int vis[1000009]; void init()
{
for(int i = 1 ; i <= 1000000 ; i++)
{
int l = 0 , t = i ;
while(t)
{
a[l++] = t % 10;
t /= 10 ;
}
for(int j = l - 1 ; j > 0 ; j--)
{
if(a[j] == 6 && a[j-1] == 2)
{
vis[i] = 1 ;
}
else if(a[j] == 4 || a[j-1] == 4)
{
vis[i] = 1 ;
}
}
}
vis[4] = 1 ;
} int main()
{
int n , m ;
init();
while(~scanf("%d%d" , &n, &m) && n + m)
{
int sum = 0 ;
for(int i = n ; i <= m ; i++)
{
if(vis[i])
{
sum++ ;
}
}
cout << (m - n + 1) - sum << endl ;
} return 0 ;
}

最新文章

  1. Putty 配图
  2. 麦咖啡阻挡正常打开Excel文件
  3. Spark运行环境的安装
  4. ZOJ 1122 Clock(模拟)
  5. 朗科U903 低级格式化后,量产错误:read onlypage (控制器芯片群联2251-03)的解决方案
  6. QList 和std::list的比较
  7. Java的进程内缓存框架:EhCache (转)
  8. 最小截断[AHOI2009]
  9. 我两年的web开发生涯
  10. 基于嵌入式操作系统VxWorks的多任务并发程序设计(2) ――任务控制
  11. nyoj Mod
  12. 第一节:EF Core简介和CodeFirst和DBFirst两种映射模式(以SQLite和SQLServer为例)
  13. python3 函数注意要点
  14. ----改写superheros的json以及上传到github----
  15. pythonのSocket
  16. Python基础之常用模块
  17. echarts - 使用echarts过程中遇到的问题(pending...)
  18. 数据分箱:等频分箱,等距分箱,卡方分箱,计算WOE、IV
  19. python项目飞机大战
  20. Mac环境下配置tomcat的步骤详解

热门文章

  1. java8中规范的四大函数式接口
  2. spring aop 实现controller 日志
  3. Python3学习笔记(十二):闭包
  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)
  5. C++入门经典-关于extern变量
  6. Mysql 基础操作命令
  7. ajaxform和ajaxgird中添加数据
  8. 五一 DAY 7
  9. C#程序 给IE网页IFRAME控件中所嵌入网页的元素赋值
  10. java:Mybatis框架3(二级缓存,延时和积极加载,SSI(Ibatis)集成,SSM集成)