标签:class turn als lld fine pac lov ++ bom
求1~n中含有49数的个数
#include<bits/stdc++.h> #define LL long long using namespace std; LL T,x,dp[50][50],shu[50]; LL dfs(LL pos,LL x,bool ok,bool limit){ if(!pos) return ok; if(!limit&&dp[pos][x]) return dp[pos][x]; LL cnt=0,up=limit?shu[pos]:9; for(LL i=0;i<=up;i++) { bool flg=false; if(x==4&&i==9) flg=true; if(ok) flg=true; cnt+=dfs(pos-1,i,flg,limit&&shu[pos]==i); } if(!limit) dp[pos][x]=cnt; return cnt; } LL slove(LL x){ LL k=0; while(x){ shu[++k]=x%10; x/=10; } return dfs(k,0,0,true); } int main() { scanf("%lld",&T); while(T--){ scanf("%lld",&x); printf("%lld",slove(x)); if(T) puts(""); } return 0; }
标签:class turn als lld fine pac lov ++ bom
原文地址:https://www.cnblogs.com/song-/p/9615533.html