网易互娱2017实习生招聘游戏研发工程师在线笔试第二场 C
偶尔碰到这题,简单数位DP题,然而我已生疏了……
这次算是重新想到的,看来对DP的理解有增进了……
dp[i][j][k],表示前i为,mod为j,是否出现2、3、5的剩下的数位可组成的数字。答案就是dp[len][0][0]
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring> using namespace std; #define LL long long LL dp[20][7][2];
int num[20]; LL dfs(int len, int mod, bool one, int show, bool flag){
if(len == 0){
if(show == 1 && mod == 0){
dp[len][mod][show] = 1;
}
else dp[len][mod][show] = 0;
return dp[len][mod][show];
}
if(!flag && dp[len][mod][show] != -1) return dp[len][mod][show]; int up = flag ? num[len]:9;
LL ans = 0, tmp = show; for(int i = 0; i <= up ; i++){
if(one && i == 8) continue;
if(i == 2 || i == 3 || i == 5) tmp = (show | 1);
// cout <<" tmp = " << tmp << endl;
ans += dfs(len - 1, (mod * 10 + i)%7, i == 1?true:false, tmp, (flag && i == up) ? true: false);
tmp = show;
// printf("%I64d====%d\n", ans, i); }
dp[len][mod][show] = ans;
return ans; } long long slove(LL n){ int len = 0;
LL tmp = n;
while(tmp){
num[++len] = tmp % 10;
tmp /= 10;
} // printf("%I64d\n", n); dfs(len, 0, false, 0, true); return dp[len][0][0]; } int main(){
long long l, r;
int T;
scanf("%d", &T);
while(T--){
memset(dp, -1, sizeof(dp));
scanf("%I64d%I64d", &l, &r);
printf("%I64d\n", slove(r) - slove(l - 1));
}
return 0;
}
网易互娱2017实习生招聘游戏研发工程师在线笔试第二场 C的更多相关文章
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...
- 2015年阿里实习生面试Java研发工程师 小记
5月5日,广州,阿里实习生面试,Java研发工程师,完全被虐orz 几乎没有Java项目开发经验,接近零基础,去水了一发,毫无悬念的被刷了..RP也是杠杠的,准备过的题目一个都没被问到,算法题也是一条 ...
- 阿里巴巴2017实习生招聘模拟题(部分)---C++后台开发方向
1.一个机器人玩抛硬币的游戏,一直不停的抛一枚不均匀的硬币,硬币有A,B两面,A面的概率为3/4,B面的概率为1/4.问第一次出现连续的两个A年的时候,机器人抛硬币的次数的期望是多少? 9/4 11/ ...
- 网易互娱23届实习笔试_3x3锯齿数独
一.输入: 输入一个3x3数独,字符'.'代表空输入三个宫的域,每个宫包括三个位置,[0,0]表示0行0列 二.输出要求: 1.每个宫里最终123各出现一次, 2.数独中的行列里不出现重复字符: 输出 ...
- 2017阿里C++研发工程师-校招-笔试模拟
题目描述: 猎人把一对兔子婴儿(一公一母称为一对)放到一个荒岛上,两年之后,它们生00下一对小兔,之后开始每年都会生下一对小兔.生下的小兔又会以同样的方式继续繁殖. 兔子的寿命都是x(x>=3) ...
- 字节跳动19春招研发第一次在线笔试-A卷
结果:凉. 说明 此博客仅为笔试记录所用,如涉及版权或保密问题,请联系我及时删除. 联系方式:georgehu716@qq.com 1. 找零 时间限制:C/C++ 1秒,其他语言 2秒 空间限制:C ...
- 【微软2017年预科生计划在线编程笔试第二场 B】Diligent Robots
[题目链接]:http://hihocoder.com/problemset/problem/1498 [题意] 一开始你有1个机器人; 你有n个工作; 每个工作都需要一个机器人花1小时完成; 然后每 ...
- 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack
[题目链接]:http://hihocoder.com/problemset/problem/1497 [题意] 给你n个皇后; 然后问你其中能够互相攻击到的皇后的对数; 皇后的攻击可以穿透; [题解 ...
随机推荐
- JavaScript——blob、file、flieReader、createObjectURL
https://blog.csdn.net/opengl_es/article/details/44336477 https://www.cnblogs.com/hhhyaaon/p/5928152. ...
- ubuntu设置root账号密码
Ubuntu Linux有一个与众不同的特点,那就是初次使用时,你无法作为root来登录系统,为什么会这样?这就要从系统的安装说起.对于其他Linux系统来 说,一般在安装过程就设定root密码,这样 ...
- vue脚手架引入swiper
方法一: 下载swiper: npm install swiper --save-dev swiper4.0使用入口:http://www.swiper.com.cn/usage/index.html ...
- 解决【npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'】方案
问题描述执行npm install的时候报错npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141 ...
- 07CSS表格
CSS表格 表格边框 如需在 CSS 中设置表格边框,请使用 border 属性. table, th, td { border: 1px solid blue; } 折叠边框 border-coll ...
- springboot Tomcat connector configured to listen on port 8081 failed to start.
启动报 Tomcat connector configured to listen on port 8081 failed to start. The port may already be in ...
- 第2节 mapreduce深入学习:2、3
第2节 mapreduce深入学习:2.MapReduce的分区:3.分区案例的补充完成运行实现 在MapReduce中,通过我们指定分区,会将同一个分区的数据发送到同一个reduce当中进行处理,例 ...
- pycharm debug后会出现 step over /step into/step into my code /force step into /step out 分别表示
1.debug,全部打印 2.打断点debug,出现单步调试等按钮,只运行断点前 3.setup over 调试一行代码 4.setup out 运行断点后面所有代码 5.debug窗口显示调试按钮 ...
- 「 HDU P4734 」 F(x)
# 题目大意 对于一个数 $x$,它的每一位数字分别是 $A_{n}A_{n-1}A_{n-2}\cdots A_{2}A_{1}$,定义其权重 $f(x)=\sum_{i=1}^{n}\left(A ...
- Python使用Flask框架,结合Highchart,自定义图表样式主题
参考链接:https://www.highcharts.com.cn/docs/themes 1.使用官方提供的主题js文件,只需要在 highcharts.js 后引入对应的文件即可,不用修改原有的 ...