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的更多相关文章

  1. 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 ...

  2. ZOJ 3962 Seven Segment Display(数位DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...

  3. zoj 3962 Seven Segment Display 数位dp

    非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...

  4. ZOJ 3962 Seven Segment Display(数位DP)题解

    题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...

  5. ZOJ - 3962 - Seven Segment Display-17省赛-数位DP

    传送门:Seven Segment Display 题意:求一个给定区间每个数字的消耗值的和: 思路:数位DP,有点区间和的思想,还有就是这个十六进制,可以用%llx读,还是比较难的: 还有就是到最大 ...

  6. 2017浙江省赛 E - Seven Segment Display ZOJ - 3962

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...

  7. 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 ...

  8. (2017浙江省赛E)Seven Segment Display

    Seven Segment Display Time Limit: 2 Seconds      Memory Limit: 65536 KB A seven segment display, or ...

  9. ZOJ 3962:Seven Segment Display(思维)

    https://vjudge.net/problem/ZOJ-3962 题意:有16种灯,每种灯的花费是灯管数目,代表0~F(十六进制),现在从x开始跳n-1秒,每一秒需要的花费是表示当前的数的花费之 ...

随机推荐

  1. centos7.3安装Nginx

    首先,如果是阿里云的centos的话,去阿里云管理端为80端口设置一组访问规则,因为阿里云默认是不开的 1. 添加Nginx yum 资源库 rpm -Uvh http://nginx.org/pac ...

  2. yield表达式形式

    首先了解 1.iterator iterator叫做迭代器,用来遍历可以序列化的数据,比如一个list,set 等,当然如果对象想要能够使用迭代器来遍历,只要在该对象的类中添加__iter__()方法 ...

  3. host元素的属性autoDeploy和reloadable的区别

    web.xml文件的修改会触发AutoDeploy,受host节的autoDeploy配置值的影响. class类文件修改会触发Reload操作,受reloadable配置值的影响. 而autoDep ...

  4. 02: docker高级篇

    1.1 Docker Compose 1.Docker Compose 介绍 1. Compose是一个定义和管理多容器的工具,使用Python语言编写. 2. 使用Compose配置文件描述多个容器 ...

  5. IDEA——找不到或无法加载主类的一种暴力解决方法

    对于用maven构建的java项目,可以利用maven工具编译一下,大致上可以解决很多奇奇怪怪的问题. 具体操作如下: 首先找到项目所在的文件夹,以F:\project为例. 删除.idea文件. 在 ...

  6. Codeforces 526F Pudding Monsters - CDQ分治 - 桶排序

    In this problem you will meet the simplified model of game Pudding Monsters. An important process in ...

  7. python使用pip下载模块

    举例下载串口模块pyserial: 下载安装了python之后,打开cmd,在python的安装目录里,搜索pip,把pip3.7.exe拖进cmd,然后输入pip3.7.exe install py ...

  8. Linux使用——Linux命令——Linux 系统基本命令使用记录

    查看系统版本信息 查看系统版本:cat /proc/version 查看cpu相关信息,包括型号.主频.内核信息:cat /proc/cpuinfo 快速了解CPU使用情况:free -h 解压文件 ...

  9. Python3基础 list + *运算 扩充列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. Ubuntu: repository/PPA 源

    在Ubuntu中,每个PPA源是单独存放在/etc/apt/sources.list.d/文件夹中的,进入到该文件夹,使用ls命令查询即可列出当前系统添加的PPA源. 添加 sudo add-apt- ...