bin巨的数(数位DP)

#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<bitset>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )typedef long long LL;typedef pair<int,int>pil;const int INF = 0x3f3f3f3f;const int maxn=1e5+100;LL l,r;int t;int num[30];LL dp[20][1800][2];int ok(int x){if(x&1) return 1;for(int i=1;i<=9;i++)if(x&(1<<i)) return 0;return 1;}LL dfs(int pos,int s,int first,int flag){if(pos==0)return first&&ok(s);if(!flag&&dp[pos][s][first]!=-1)return dp[pos][s][first];LL ans=0;int ed=flag?num[pos]:9;for(int i=0;i<=ed;i++){int f=first;if(!first&&i) f=1;if(f&&i==0) ans+=dfs(pos-1,s|1,f,flag&&i==ed);else if(!f&&!i) ans+=dfs(pos-1,s,f,flag&&i==ed);else ans+=dfs(pos-1,s^(1<<i),f,flag&&i==ed);}if(!flag) dp[pos][s][first]=ans;return ans;}LL solve(LL x){if(x==0) return 1;int pos=0;while(x){num[++pos]=x%10;x/=10;}return dfs(pos,0,0,1)+1;}int main(){CLEAR(dp,-1);scanf("%d",&t);while(t–){scanf("%lld%lld",&l,&r);LL ans=solve(r)-solve(l-1);printf("%lld\n",ans);}return 0;}

,并且为之实践了关怀和付出的善举。对于我性情中的易感和怨薄,

bin巨的数(数位DP)

相关文章:

你感兴趣的文章:

标签云: