# ACM-DP-数位dp 2017浙江省赛E题Seven Segment Display

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
using namespace std;
const long long maxn=(long long)0xffffffff;
int num[16]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4};
int dig[20];
long long dp[20][205];
const int mod=16;
int t;
long long e,s;
long long dfs(int pos,long long sum,bool limit){
if(pos==-1)return sum;
if(!limit&&dp[pos][sum]!=-1)return dp[pos][sum];
int up=limit?dig[pos]:mod-1;
long long tmp=0;
for(int i=0;i<=up;i++){
tmp+=dfs(pos-1,sum+num[i],limit&&i==dig[pos]);
}
if(!limit)dp[pos][sum]=tmp;
return tmp;
}
long long solve(long long x){
for(int i=0;i<8;i++){
dig[i]=x%mod;
x/=mod;
}
return dfs(7,0,1);
}
int main(){
scanf("%d",&t);
memset(dp,-1,sizeof(dp));
while(t--){
scanf("%lld %llX",&e,&s);
e--;
e=e+s;
if(e>maxn){//ffffffff
e=e%(maxn+1);//fffffffff+1
printf("%lld\n",solve(maxn)-solve(s-1)+solve(e));//ffffffff
}
else printf("%lld\n",solve(e)-solve(s-1));
}
return 0;
}

1.计算每个八位数值n到00000000的前缀和

for(00000000->*******n)ans+=(sumnum[1-8]);
}
2.递归处理的思想

80000000之前的前缀和(00000000,1(7*0),2(7*0)...)
8*******循环向下重复当前相同的操作
9000000之前的前缀和
9******循环向下......
3.找规律

4.scanf真好用，差不多骚操作就这些了，祝AC快乐

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<string.h>
using namespace std;
const long long maxn=(long long)0xffffffff;
int num[17]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4,78};
long long du[8];
int dig[10];
const int mod=16;
int t;
long long e,s;
long long solve(long long x){
long long q=x,l=x;
for(int i=0;i<8;i++){
dig[i]=x%mod;
x/=mod;
}
long long sum=0;
for(int i=7;i>=0;i--){
if(dig[i]){
long long temp=0;
//79999999-00000000
for(int j=0;j<dig[i];j++){
temp+=num[j]*du[i];
temp+=num[16]*du[i-1]*i;//i位
}
q=0;
for(int j=i-1;j>=0;j--)q+=dig[j]*du[j];
//80000000-89ABCDEF里‘8’出现了9ABCDEF+1次
temp+=(q+1)*num[dig[i]];//q这个数时(0-q)有q+1个
sum+=temp;
}
else sum+=(q+1)*num[0];//q这个数时(0-q)有q+1个
}
//printf("l=%lld.sum=%lld\n",l,sum);
return sum;
}
int main(){
scanf("%d",&t);
du[0]=1;
for(int i=1;i<8;i++)du[i]=du[i-1]*mod;
while(t--){
scanf("%lld %llX",&e,&s);
e=e-1;
e=e+s;
if(e>maxn){
e=e-(maxn+1);
//printf("maxn=%lld     s-1=%lld      e=%lld\n",solve(maxn),solve(s-1),solve(e));
printf("%lld\n",solve(e)-solve(s-1)+solve(maxn));
}
else {
printf("%lld\n",solve(e)-solve(s-1));
}
}
return 0;
}