意甲冠军:求0-B见面<=F[A]所有可能的

思维:数字DP,内存搜索

#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[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;
}

HDU - 4734 F(x) (2013成都网络游戏,数字DP)的更多相关文章

  1. HDU 4734 F(x) 2013 ACM/ICPC 成都网络赛

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小 ...

  2. 【数位DP】 HDU 4734 F(x)

    原题直通车:HDU 4734 F(x) 题意:F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1, 求0.....B中F[x]<=F[A ...

  3. HDU 4734 F(x) (2013成都网络赛,数位DP)

    F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HDU 4733 G(x) (2013成都网络赛,递推)

    G(x) Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. HDU 4734 - F(x) - [数位DP][memset优化]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Lim ...

  6. hdu 4734 F(x)(数位dp+优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2 ...

  7. HDU - 4734 F(x) (数位dp)

    For a decimal number x with n digits (A nA n-1A n-2 ... A 2A 1), we define its weight as F(x) = A n  ...

  8. HDU 4734 F(x) ★(数位DP)

    题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少 ...

  9. HDU 4734 F(x)

    这题可能非递归版好写? #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

随机推荐

  1. 【u244】山地考察

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 地质学家们打算考察一片山区.这片山区可分成m*n的网格,每个网格都有唯一的海拔高度,山区外围的海拔高度 ...

  2. [TypeStyle] Add type safety to CSS using TypeStyle

    TypeStyle is the only current CSS in JS solution that is designed with TypeSafety and TypeScript dev ...

  3. stackedit

    https://github.com/benweet/stackedit/ https://github.com/waltcow/blog/issues/4

  4. Multi-core compute cache coherency with a release consistency memory ordering model

    A method includes storing, with a first programmable processor, shared variable data to cache lines ...

  5. 最简单的基于FFmpeg的AVUtil样例 (AVLog, AVOption等)

    本文的演示样例程序记录了FFmpeg的libavutil中几种工具函数的用法: AVLog:日志输出AVOption (AVClass):选项设置AVDictionary:键值对存储ParseUtil ...

  6. windows 空闲超时 非管理员如何破解

    windows 空闲超时 非管理员如何破解

  7. C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结。

    C++/Php/Python/Shell 程序按行读取文件或者控制台方法总结. 一.总结 C++/Php/Python/Shell 程序按行读取文件或者控制台(php读取标准输入:$fp = fope ...

  8. MySQL中关于OR条件的优化

    转载 MySQL在 5.0版本中引入新特性:索引合并优化(Index merge optimization),当查询中单张表可以使用多个索引时,同时扫描多个索引并将扫描结果进行合并. 该特新主要应用于 ...

  9. [HTML5] Using the tabindex attribute for keyboard accessibility

    You can make any element keyboard interactive with the HTML tabindex attribute. But you might need a ...

  10. [转]mnesia数据库学习笔记

    mnesia数据库学习笔记一 mnesia数据库学习笔记二 mnesia数据库学习笔记三 mnesia数据库学习笔记四