Seven Segment Display

上次训练赛碰到这题不会数位DP,抄了个板子过的,今天瞎搞了一个不用DFS实现的数位DP,类似的套路也已经再HDU过了几道题了。
Seven Segment Display

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=20;
LL f[N][N];
int s[]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4};
int power[20];
LL dp(LL n){
	if(n==0) return s[0]*8;
	vector<int> nums;
	for(int i=1;i<=8;++i){
		nums.push_back(n%16);
		n/=16;
	}
	LL res=0,last=0;
	for(int i=nums.size()-1;i>=0;--i){
		int x=nums[i];
		for(int j=0;j<x;++j){
			res+=f[i+1][j]+power[i]*last;
		}
		last+=s[x];
	}
	res+=last;
	return res;
}
int main(){
	power[0]=1;
	for(int i=1;i<=10;++i) power[i]=power[i-1]*16;
	int res=0,p=16;
	for(int i=0;i<16;++i) f[1][i]=s[i],res+=s[i];//cout<<res<<endl;
	for(int i=2;i<9;++i,p*=16){
		for(int j=0;j<16;++j){
			f[i][j]=s[j]*p;
			for(int k=0;k<16;++k){
				f[i][j]+=f[i-1][k];
			}
		}
	}
	res=0;
	int T;
	cin>>T;
	while(T--){
        LL n,m,t=0xFFFFFFFF;
	    scanf("%lld%llX",&n,&m);
        LL l=m;
        LL r=m+n-1;
        if(r>t)
            cout<<dp(t)+dp(r%(t+1))-(l==0?0:dp(l-1))<<endl;
        else cout<<dp(r)-(l==0?0:dp(l-1))<<endl;
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值