hdu 3943
数位dp
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <vector>
#include <sstream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iostream>
#define maxn 105
#define INF 0x3f3f3f3f
#define inf 10000000
#define MOD 100000000
#define ULL unsigned long long
#define LL long long
#define _setm(houge) memset(houge, INF, sizeof(houge))
#define _clear(houge) memset(houge, 0, sizeof(houge))
using namespace std; LL dp[25][25][25], p, q;
int dig[25], x, y; void init() {
_clear(dp);
dp[0][0][0] = 1;
for(int i = 1; i <= 20; ++ i) {
for(int j = 0; j <= i; ++ j) {
for(int k = 0; k+j <= i; ++ k) {
dp[i][j][k+1] += dp[i-1][j][k];
dp[i][j+1][k] += dp[i-1][j][k];
dp[i][j][k] += dp[i-1][j][k]*8;
}
}
}
} int getdig(LL nx) {
_clear(dig);
int cnt = 0;
while(nx) {
dig[++cnt] = nx%10;
nx /= 10;
}
return cnt;
} LL countid(LL nx) {
int cnt = getdig(nx);
LL ans = 0;
int cx = x, cy = y;
for(int i = cnt; i > 0; -- i) {
for(int j = 0; j < dig[i]; ++ j) {
if(j == 4 && cx) ans += dp[i-1][cx-1][cy];
else if(j == 7 && cy) ans += dp[i-1][cx][cy-1];
else if(j != 4 && j != 7) ans += dp[i-1][cx][cy];
}
if(dig[i] == 4) cx --;
if(dig[i] == 7) cy --;
if(cx < 0 || cy < 0) break;
}
return ans;
} LL findd(LL k) {
int len = 1;
while(!(dp[len-1][x][y] < k && dp[len][x][y] >= k)) ++ len;
long long res = 0;
int cx = x, cy = y;
for(int i = len; i > 0; -- i)
for(int j = 0; j < 10; ++ j) {
int tx = cx, ty = cy;
if(j == 4) {
-- tx;
if(tx < 0)
continue;
}
if(j == 7) {
-- ty;
if(ty < 0)
continue;
}
if(dp[i-1][tx][ty] >= k) {
res = res*10+j;
cx = tx;
cy = ty;
break;
}
k -= dp[i-1][tx][ty];
}
return res;
} int main()
{
int t, ca = 0;
init();
scanf("%d", &t);
while(t --) {
scanf("%I64d%I64d%d%d", &p, &q, &x, &y);
LL a = countid(p+1), b = countid(q+1);
int n;
scanf("%d", &n);
printf("Case #%d:\n", ++ ca);
while(n --) {
LL k;
scanf("%I64d", &k);
if(k > b-a) puts("Nya!");
else printf("%I64d\n", findd(k+a));
}
}
return 0;
}
hdu 3943的更多相关文章
- HDU 3943 K-th Nya Number(数位DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3943 题目大意:求出区间 (P,Q] 中找到第K个满足条件的数,条件是该数包含X个4和Y个7 Samp ...
- HDU 3943 K-th Nya Number
K-th Nya Number Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on HDU. Origina ...
- HDU 3943 数位dp+二分
K-th Nya Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) ...
- hdu 3943 经典数位dp好题
/* 题意:求出p-q的第j个nya数 数位dp,求出p-q的所有nya数的个数很好求,但是询问求出最终那个第j个值时是我不会求了看了下别人的思路 具体就是把p-q的第j个转化成0-q的第low+j个 ...
- My_Plan part1 小结
数位DP AC十道题目以上 成就达成 八月份!三个月!想想就令人兴奋呢 开始写总结啦 貌似简单的数位DP只需要改改模板就可以啦 就按照我的做题顺序开始总结吧 先是学习了一发模板:http://www. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- CENTOS6.4上KVM虚拟机环境搭建
CENTOS6.4上KVM虚拟机环境搭建 关键词: KVM,虚拟机,windows7, VNC, 桥接网络,br0, SCSI, IDE 环境: host: CENTOS6.4 guest: ...
- vijos 1053 Easy sssp
描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,000)条边的带权有向图. 要求你写一个程序, 判断这个有向图中是否存在负权回路. 如果从一 ...
- 如何使用SAP CRM Marketing Survey创建一个市场问卷调查
使用事务码CRM_SURVEY_SUITE进行编辑.选中Activities这个应用类型,点击新建按钮: 双击Survey的根节点,点击编辑按钮维护Suvey的标题: Survey的正文布局类型(La ...
- Windows程序设计1(工具、编码、窗口)
一.几个常用小工具: 1. 编译器:CL.EXE 将源文件转变为目标文件(汇编语言). CL.EXE /c xxx.c 或 xx.cpp cl.exe -? 显示cl帮助 cl.exe ...
- 迅为iMX6UL Cortex-A7架构单核ARM开发板接口介绍-支持定制
支持商业级和工业级核心板 1. POWER 电源接口电源输入为 5V/2A+,给核心板提供 5V 电源,给底板供电.原理图部分如下图所示. 电源接口位置如下图所示. 2. SWITCH 电源开关轻触电 ...
- 众皓网络(T 面试)
1.你们项目中哪里用到了Redis? 2.Redis中存储的数据,你们什么时候进行更新? 3.你用过消息队列吗? 4.你写的这个微服务项目拆分成了几个服务? 5.SpringCloud项目怎么部署的?
- Android studio Github 断开连接
http://blog.csdn.net/agoodcoolman/article/details/50562301 使用软件:Android studio svn:Github 从github直接从 ...
- 转:使用 /proc 文件系统来访问 Linux 内核的内容
使用 /proc 文件系统来访问 Linux 内核的内容 https://www.ibm.com/developerworks/cn/linux/l-proc.html /proc 文件系统并不是 G ...
- 小白菜OJ 1122 公牛母牛配(最大二分图匹配模板)
题意: n只公牛和m只母牛,某些公牛和某些母牛互相喜欢.但最后一只公牛只能和一只母牛建立一对一匹配.要使得最后牛群匹配对数最大. 链接: http://caioj.cn/problem.php?id= ...
- Python数据结构--搜索树
''' 二叉搜索树(BST)是一棵树,其所有节点都遵循下述属性 - 节点的左子树的键小于或等于其父节点的键. 节点的右子树的键大于其父节点的键. 因此,BST将其所有子树分成两部分; 左边的子树和右边 ...