HDU-4734 F (x) (2013 All online games, digital DP)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.