标签:des style blog class code c
3 0 100 1 10 5 100
Case #1: 1 Case #2: 2 Case #3: 13
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <string> #include <algorithm> #include <queue> using namespace std; int dp[12][4600]; int A,B; int F; vector <int> digit; void init(){ F = 0; int t = 0; while(A){ F += (A%10)*(1<<t); t++; A/=10; } } int dfs(int pos,int val,int done){ if(pos==-1) return 1; if(!done&& ~dp[pos][val]) return dp[pos][val]; int res = 0; int end = done?digit[pos]:9; for(int i = 0; i <= end; i++){ if(val + i*(1<<pos) > F) break; res += dfs(pos-1,val + i*(1<<pos),done&&i==end); } if(!done) dp[pos][val] = res; return res; } int solve(int num){ digit.clear(); while(num){ digit.push_back(num%10); num /= 10; } return dfs(digit.size()-1,0,1); } int main(){ int ncase,T = 1; cin >> ncase; memset(dp,-1,sizeof dp); while(ncase--){ cin >> A >> B; init(); printf("Case #%d: %d\n",T++,solve(B)); } return 0; }
标签:des style blog class code c
原文地址:http://blog.csdn.net/mowayao/article/details/25998705