Serie A champion: Ask 0-b to meet <=f[a] all possible
Thinking: Digital DP, Memory search
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio>using namespace Std;int A, B;int dp[20][200000];int bit[20];int dfs (int cur, int num, int flag) {if (cur = =-1) return num >= 0;if (num < 0) return 0;if (!flag && dp[cur][num]! =-1) return dp[cur][num]; int ans = 0;int end = flag?bit[cur]:9;for (int i = 0; I <= end; i++) ans + = DFS (cur-1, num-i* (1<<cur), flag&&i==end); if (!flag) DP[CU R][num] = Ans;return ans;} int F (int x) {int tmp = 0;int len = 0;while (x) {tmp + = (x%10) * (1<<len); len++;x/= 10;} return TMP;} int cal () {int len = 0;while (B) {bit[len++] = b%10; B/= 10;} Return Dfs (len-1, F (A), 1);} int main () {int t;int cas = 1;scanf ("%d", &t), Memset (DP,-1, sizeof (DP)), while (t--) {scanf ("%d%d", &a, &b);p R intf ("Case #%d:%d\n", cas++, Cal ());} return 0;}
HDU-4734 F (x) (2013 All online games, digital DP)