标签:points number int rip ash ret panel man rmi
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 19122 Accepted Submission(s): 7068
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> #include<cmath> #define ls (u<<1) #define rs (u<<1|1) #define maxn 30 #define ll long long #define INF 1e18+7 using namespace std; #define max(a,b) (a)>(b)?(a):(b) #define min(a,b) (a)<(b)?(a):(b) int digit[maxn]; ll dp[maxn][3]; ll dfs(int pos,int flag,int limit){ if(pos == -1){ return flag == 2;//flag等于2的时候代表这个数满足条件 } if(!limit && dp[pos][flag]!=-1){//达到极限且此时dp有值 return dp[pos][flag]; } ll sum = 0; int e = limit?digit[pos]:9; for(int i=0;i<=e;i++){ int have = flag; if(flag == 1 && i == 9){ have = 2; } if(flag == 0 && i == 4){ have = 1;//此时为将要完成的状态 } if(flag == 1 && i!=4 && i!=9){ have = 0; } sum += dfs(pos-1,have,limit&&i==e); } if(!limit){//达到极限的情况 dp[pos][flag] = sum; } return sum; } ll solve(ll n){ int pos = 0; while(n){ digit[pos++] = n%10; n /= 10; } return dfs(pos-1,0,1); } int main(){ int T; scanf("%d",&T); while(T--){ ll n; scanf("%lld",&n); memset(dp,-1,sizeof(dp)); printf("%lld\n",solve(n)); } return 0; }
标签:points number int rip ash ret panel man rmi
原文地址:http://www.cnblogs.com/l609929321/p/7291335.html