zoj 3962
数位DP 还有一部分没写
#include <iostream> #include<string.h> #include<stdio.h> using namespace std ; #define ll long long int num[16]={6,2,5,5,4,5,6,3,7,6,6,5,4,5,5,4}; ll dp[10][200]; int dig[10]; ll dfs(int len,int sum,int e) { if(len<1) return sum; if(!e&&dp[len][sum]!=-1) return dp[len][sum]; int u=e?dig[len]:15; ll tmp=0; for(int i=0;i<=u;i++) tmp+=dfs(len-1,sum+num[i],e&&(i==dig[len])); if(!e) dp[len][sum]=tmp; return tmp; } ll solve(ll a) { for(int i=1;i<=8;i++) { dig[i]=a%16; a=a/16; } return dfs(8,0,1); } int main() { memset(dp,-1,sizeof(dp)); int t; scanf("%d",&t); while(t--) { ll r,n; scanf("%lld %llx",&r,&n); printf("%lld\n",solve(n+r-1)-solve(n-1)); } return 0; }
posted on 2017-05-14 21:17 HelloWorld!--By-MJY 阅读(182) 评论(0) 编辑 收藏 举报