ZOJ 3962 Seven Segment Display
思路:
经典数位dp
代码:
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) int cost[]={,,,,,,,,,,,,,,,};
int d[];
LL dp[][];
LL dfs(int pos,int sum,bool limit){
if(pos<)return sum;
if(!limit&&~dp[pos][sum])return dp[pos][sum];
int top=limit?d[pos]:;
LL t=;
for(int i=;i<=top;i++){
t+=dfs(pos-,sum+cost[i],limit&&i==d[pos]);
}
if(!limit)dp[pos][sum]=t;
return t;
}
LL solve(LL n){
for(int i=;i<;i++){
d[i]=n%;
n/=;
}
return dfs(,,true);
}
int main(){
LL n,m,l,r;
int T;
LL s=;
mem(dp,-);
scanf("%d",&T);
while(T--){
scanf("%lld%llX",&n,&m);
l=m;
r=m+n-;
if(r>s){
printf("%lld\n",solve(r-s-)+solve(s)-solve(l-));
}
else{
printf("%lld\n",solve(r)-solve(l-));
}
}
return ;
}
ZOJ 3962 Seven Segment Display的更多相关文章
- ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。
Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...
- ZOJ 3962 Seven Segment Display(数位DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...
- zoj 3962 Seven Segment Display 数位dp
非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...
- ZOJ 3962 Seven Segment Display(数位DP)题解
题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...
- ZOJ - 3962 - Seven Segment Display-17省赛-数位DP
传送门:Seven Segment Display 题意:求一个给定区间每个数字的消耗值的和: 思路:数位DP,有点区间和的思想,还有就是这个十六进制,可以用%llx读,还是比较难的: 还有就是到最大 ...
- 2017浙江省赛 E - Seven Segment Display ZOJ - 3962
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...
- ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display Time Limit: 1 Second Memory Limit: 65536 KB A seven segment display, or s ...
- (2017浙江省赛E)Seven Segment Display
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
- ZOJ 3962:Seven Segment Display(思维)
https://vjudge.net/problem/ZOJ-3962 题意:有16种灯,每种灯的花费是灯管数目,代表0~F(十六进制),现在从x开始跳n-1秒,每一秒需要的花费是表示当前的数的花费之 ...
随机推荐
- Vue基础进阶 之 计算属性的使用
计算属性的基本使用 初始小示例: 代码: window.onload = () =>{ new Vue({ el:'div', data:{ msg:'' } }) } </script& ...
- jQuery知识总结(转)
原文:http://fwhyy.com/2013/04/jquery-knowledge-summary/ 这篇文章在于筛选器的简单例子,让人一看就懂代码的作用 20170223 前言 jQuery一 ...
- win-Linux文件脚本迁移过程中的问题 syntax error: unexpected end of file
问题: 在win下写好的shell脚本,放到Linux上测试sh -n报错如下 ORA_check.sh: line 251: syntax error: unexpected end of fil ...
- 牛客网校招全国统一模拟笔试(三月场)- Java方向
1.若二叉树采用二叉链表存储结构,要交换其所有分支结点左.右子树的位置,利用()遍历方法最合适 A 前序 B 中序 C 后序 D 按层次 解析:显然后序遍历比较合理.正常的逻辑应该就是:做好当前结点子 ...
- topcoder srm 699 div1 -3
1.两个长度为$n$的数组$a,b$,$0 \leq a_{i} <2^{30}$.$b_{i}=-1$或者$b_{i}$为除$a_{i}$外其他数字的抑或值.现在给定$b$,如果不存在$a$, ...
- Linux电源管理(五)thermal【转】
本文转载自:https://blog.csdn.net/zhouhuacai/article/details/78172267 版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...
- dll注入到指定进程
talk is cheap,show me code 代码有详细注释 主程序 #include "stdafx.h" #include <windows.h> #inc ...
- hihoCoder week4 Trie图
ac自动机 题目链接 https://hihocoder.com/contest/hiho4/problem/1 参考:https://blog.csdn.net/baidu_30541191/art ...
- P4145 上帝造题的七分钟2 / 花神游历各国
思路 每个数不会被开方超过log次,对每个数暴力开方即可 代码 #include <algorithm> #include <cstring> #include <cst ...
- (zhuan) 一些RL的文献(及笔记)
一些RL的文献(及笔记) copy from: https://zhuanlan.zhihu.com/p/25770890 Introductions Introduction to reinfor ...