标签:空间 esc nbsp mes hdu out -- iostream ott
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define ll long long int using namespace std; inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int dir[2][2]={1,0 ,0,1}; int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1}; const int inf=0x3f3f3f3f; int bits[10]; int dp[10][10007]; //len位 需要凑sum的权值和 int fa; int v[11]={1,2,4,8,16,32,64,128,256,512}; int dfs(int len,int sum,bool ismax){ if(!len) return sum<=fa; if(sum>fa) return 0; if(!ismax&&dp[len][fa-sum]>=0) return dp[len][fa-sum]; int up=ismax?bits[len]:9; int cnt=0; for(int i=0;i<=up;i++){ cnt+=dfs(len-1,sum+i*v[len-1],ismax&&i==up); } if(!ismax) dp[len][fa-sum]=cnt; return cnt; } int solve(int x){ int len=0; while(x){ bits[++len]=x%10; x/=10; } return dfs(len,0,true); } void cal(int a){ int now=1; while(a){ fa+=now*(a%10); a/=10; now*=2; } } int main(){ int t; scanf("%d",&t); int w=0; memset(dp,-1,sizeof(dp)); while(t--){ fa=0; int a,b; scanf("%d%d",&a,&b); cal(a); printf("Case #%d: %d\n",++w,solve(b)); } return 0; }
标签:空间 esc nbsp mes hdu out -- iostream ott
原文地址:https://www.cnblogs.com/wmj6/p/10817174.html