题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734

  注意到F(x)的值比较小,所以可以先预处理所有F(x)的组合个数。f[i][j]表示 i 位数时F(x)为 j 的个数,方程容易转移:f[i][1<<i+j]=sigma( f[i][j] )。然后求一下f[i][j]的前缀和,就可以直接统计了。。

 //STATUS:C++_AC_31MS_684KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef __int64 LL;
typedef unsigned __int64 ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End int f[][N];
int T,n,m; int getfa(int a)
{
int i,ret=;
for(i=;a;i++,a/=)
ret+=(a%)*(<<i);
return ret;
} int solve()
{
int i,j,k,acc=,fa,len,t,ret=;
int num[];
for(len=,t=m;t;t/=)num[++len]=t%;
fa=getfa(n);
for(i=len;i>=;i--){
for(j=;j<num[i];j++){
if(fa-acc-j*(<<(i-))>=)ret+=f[i-][fa-acc-j*(<<(i-))];
}
acc+=j*(<<(i-));
}
if(acc<=fa)ret++;
return ret;
} int main(){
// freopen("in.txt","r",stdin);
int i,j,k,t,ca=;
f[][]=;
for(i=;i<=;i++){
for(j=;j<;j++){
t=j*(<<(i-));
for(k=;t+k<N;k++)
f[i][t+k]+=f[i-][k];
}
}
for(i=;i<=;i++)
for(j=;j<N;j++)f[i][j]+=f[i][j-];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
printf("Case #%d: %d\n",ca++,solve());
}
return ;
}

HDU-4734 F(x) 数位DP的更多相关文章

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

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

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

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

  3. 【数位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 ...

  4. HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛

    普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ ...

  5. 题解——HDU 4734 F(x) (数位DP)

    这道题还是关于数位DP的板子题 数位DP有一个显著的特征,就是求的东西大概率与输入关系不大,理论上一般都是数的构成规律 然后这题就是算一个\( F(A) \)的公式值,然后求\( \left [ 0 ...

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

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

  7. hdu 4389 X mod f(x) 数位DP

    思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> # ...

  8. 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的时候的个数,然后需要预处理下小 ...

  9. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  10. HDU 5787 K-wolf Number 数位DP

    K-wolf Number Problem Description   Alice thinks an integer x is a K-wolf number, if every K adjacen ...

随机推荐

  1. Google Hacking技术

    (1)google hack database https://www.exploit-db.com/google-hacking-database/ (2)查找包含某关键字的特定类型文件 命令:关键 ...

  2. Android getActionBar()报空指针异常

    1. 加载完视图后,再去获取: 写在setContentView()后面. 2.sdk版本: Actionbar的主题在3.0以后才有,使用的时候要确保,最低的版本不能小于3.0. <uses- ...

  3. Failed to allocate memory: 8

    Failed to allocate memory: 8This application has requested the Runtime to terminate it in an unusual ...

  4. th固定 td滚动的表格实现

    为什么这样? 体验好 原理 通过两个表格,使其th td 对应,产生一种错觉. 代码 1.html <div class="content"> <div clas ...

  5. 宏buf_pool_t

    typedef struct buf_pool_struct buf_pool_t; struct buf_pool_struct{ /** @name General fields */ /* @{ ...

  6. MySQL Timeout解析

    “And God said, Let there be network: and there was timeout”在使用MySQL的过程中,你是否遇到了众多让人百思不得其解的Timeout?那么这 ...

  7. shiro实现APP、web统一登录认证和权限管理

    先说下背景,项目包含一个管理系统(web)和门户网站(web),还有一个手机APP(包括Android和IOS),三个系统共用一个后端,在后端使用shiro进行登录认证和权限控制.好的,那么问题来了w ...

  8. yum install错误 系统环境:Oracle Linux5.4 在通过yum安装软件时出现以下错误:

    1.yum配置文件 1 [root@rh168 yum.repos.d]# cat yum.repo  2 [base] 3 name=Oracle linux  4 baseurl=file:/// ...

  9. U1 - A 留在电脑里的字体

    U1系列新篇章,实战派!说说常用的字体! U1系列新篇章,实战派!更多干货更多关于软件的使用等即将放出,大家敬请期待!!

  10. 零基础编程指南(By Turtle)

    [零.基础] 1.看文章:<程序猿搜索的技巧>(未完成) [一.入门] 学习语言:VB 安装:下载VB6即可 教程:<李天生vb从入门到精通>http://www.xin372 ...