标签:bom time java lin mit 代码 miss erro desc
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 19698 Accepted Submission(s): 7311
#include<iostream> #include<cstring> #define LL long long using namespace std; LL bit[25], dp[25][2]; LL dfs(int pos, int is4, int lim) { if(pos<0) return 1; if(!lim && dp[pos][is4]!=-1) return dp[pos][is4]; int las=lim?bit[pos]:9; LL res=0; for(int i=0; i<=las; ++i) if(!(is4 && i==9)) res+=dfs(pos-1, i==4, lim&&i==las); if(!lim) dp[pos][is4]=res; return res; } int main() { int T; memset(dp, -1, sizeof(dp)); cin>>T; while(T--) { LL n; cin>>n; LL len=0, m=n; while(n) { bit[len++]=n%10; n/=10; } LL ans=m-dfs(len-1, 0, 1)+1; cout<<ans<<endl; } return 0; }
标签:bom time java lin mit 代码 miss erro desc
原文地址:http://www.cnblogs.com/xiepingfu/p/7439983.html