标签:iostream click else sig sizeof you 思路 closed max
#include<iostream> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #define fuck(x) cout<<#x<<" = "<<x<<endl; #define ls (t<<1) #define rs ((t<<1)+1) using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn = 100086; const int inf = 2.1e9; const ll Inf = 999999999999999999; const int mod = 1000000007; const double eps = 1e-6; const double pi = acos(-1); int bit[20]; ll dp[20][4]; //sta表示三种状态。 //1:pos结尾处是4 //2:pos之前有49 //0:不含以上两种情况 ll dfs(int pos,int sta,bool limit){ if(pos==-1&&sta==2){return 1ll;} else if(pos==-1){return 0;} else if(!limit&&dp[pos][sta]!=-1){ return dp[pos][sta]; } int up=limit?bit[pos]:9; ll ans=0; for(int i=0;i<=up;i++){ if(sta==2||(sta==1&&i==9)){//之前有49或者刚刚凑齐一个 ans+=dfs(pos-1,2,limit&&i==up); } else if(i==4){//pos结尾处是4 ans+=dfs(pos-1,1,limit&&i==up); } else{ ans+=dfs(pos-1,0,limit&&i==up); } } if(!limit){dp[pos][sta]=ans;}//没有限制才能赋值给dp。 return ans; } ll solve(ll t){ int pos=0; while(t){ bit[pos++]=t%10; t/=10; } return dfs(pos-1,0,true); } int main() { int T; scanf("%d",&T); memset(dp,-1,sizeof(dp)); while(T--){ ll n; scanf("%lld",&n); printf("%lld\n",solve(n)); } return 0; }
标签:iostream click else sig sizeof you 思路 closed max
原文地址:https://www.cnblogs.com/ZGQblogs/p/10674349.html