意甲冠军:求0-B见面<=F[A]所有可能的
思维:数字DP,内存搜索
#include#include #include #include 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[cur][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); printf("Case #%d: %d\n", cas++, cal()); } return 0; }