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]的个数. 代码: // 31MS 548K 931 B G++ #include<iostream> #include<cstdio> #include<cstring> using namespace std; int digit[11], dp[11][6000],…
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4734 数位DP. 用dp[i][j][k] 表示第i位用j时f(x)=k的时候的个数,然后需要预处理下小于k的和,然后就很容易想了 dp[i+1][j][k+(1<<i)]=dp[i][j1][k];(0<=j1<=j1) AC代码: #include <iostream> #include <cstdio> #include <cstring> #i…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 题意:我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~b有多少个不大于f(a)的数 显然这题可以设这样的dp dp[len][count]表示前len位权值为count的有多少,然后显然的在len==0时return count>=f(a); 但是这样…
这题可能非递归版好写? #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ][],ret=,bit[]; void get_table() { ;i<=;i++) dp[][i]=; ;i<=;i++) dp[][i]=; ;i<=;i++) ;j<=;j++) ;k<=;k++) <…
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 * 2 n-1 + A n-1 * 2 n-2 + ... + A 2 * 2 + A 1 * 1. Now you are given two numbers A and B, please calculate how many numbers are there between 0 and B,…
这道题还是关于数位DP的板子题 数位DP有一个显著的特征,就是求的东西大概率与输入关系不大,理论上一般都是数的构成规律 然后这题就是算一个\( F(A) \)的公式值,然后求\( \left [ 0 ,  B \right ] \)区间内\( F(x) \)不大于\( F(A) \)的数的个数 所以由数据范围很容易得到计算出最大值不会超过4600 然后我们设状态\( dp[10][4600][4600] \)表示不同\( F(A) \)取值下的第\( pos \)个位置的值总和为 \( sumx…
F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 382    Accepted Submission(s): 137 Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x…
题意 一个整数 (AnAn-1An-2 ... A2A1), 定义 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,求[0..B]内有多少数使得F(x) <= F(A).多组数据,T <= 10000 思路 成都网赛--都是泪T_T-- 很裸的数位DP--一开始我的dp状态是dp[pos][fx],fx表示当前枚举到fx为多少,判断fx<=fa.但这样设计状态的一个问题是对于不同的A,dp[][]表示的状态不同,所以每个T都有…
题意:  一个非负整数的十进制位是这样的 (AnAn-1An-2 ... A2A1),定义F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1.给出A和B,问[0,B]中有几个整数x的F(x)值<=F(A)? 思路: 算一下就知道F(x)值不会超过512*9,而B仅仅有8位十进制数,那么8*512*9就可以算出所有的统计了.对于每个询问,先计算F(A)的值,然后统计小于此值有几个就行了.统计的复杂度也是很低的.若是以前缀和来统计后面的个数的…
意甲冠军:求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 == -…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4734 F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4389    Accepted Submission(s): 1614 Problem Description For a decimal number x with…
http://acm.hdu.edu.cn/showproblem.php?pid=4734 一般数位dp表示的是数的性质,这个题目也是一样,但是我们求出来的是一个函数的值,怎么把这个值转化成一类数,然后再用dp数字来表示这个数的性质呢? 这个我觉得挺麻烦的,很自然发现了这个f[x]并不是很大,最大应该就是10000左右,所以就可以放入数组里面表示 所以就有dp[pos][sum] 但是呢,这个是有问题的,因为如果你用sum来表示前缀和,那就无法进行记忆化,这个dp数组就会出现问题. 然后我就懵…
题意: 给你一个n位的数x(A(n)A(n-1)...A(1)),那么F(x)=A(n)*2^(n-1)+A(n-1)*2^(n-2)......+A(1)*2^(0) 题目输入A.B 你需要找出来在[0,B]这个范围内有多少个数的F(x)大于F(A) 题解: 这个就是卡memset函数的,而且要注意dp方程的选定 注释+正确代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #inc…
题意: 我们定义十进制数x的权值为f(x) = a(n)*2^(n-1)+a(n-1)*2(n-2)+...a(2)*2+a(1)*1,a(i)表示十进制数x中第i位的数字. 题目给出a,b,求出0~b有多少个不大于f(a)的数. 思路: 数位DP,用来学习数位DP了. <数位DP> 所谓数位DP就是基于考虑数字的每一位来转移的DP. 例如求比456小的数,可以这么考虑, 4          5               6   4       5             (0~6) 4…
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4579 Accepted Submission(s): 1610 Problem Description Giving the N, can you tell me the answer of F(N)? Input Each test case contains a si…
题目链接:HDU 2009-4 Programming Contest 分析:具有一定的周期性——4018处理下就可以A了 Sample Input Sample Output AC代码: #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<iostream> #include<queue> #include<map>…
F - Finding Seats Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1937 Description A group of K friends is going to see a movie. However, they are too late to get good tickets, so they are looki…
E - Tunnel Warfare HDU - 1540 对这个题目的思考:首先我们已经意识到这个是一个线段树,要利用线段树来解决问题,但是怎么解决呢,这个摧毁和重建的操作都很简单,但是这个查询怎么查呢, 这个是不是要判断这一个点左边和右边最远的距离,然后相加起来就可以了,所以就是维护一个区间最左边和最右边的值,然后把他们合并就是最大值. 这个最左边的值 pre_max = 子左节点的 pre_max 如果这个 pre_max==len 那就可以合并子右节点的 pre_max 最右值同理 这个…
题意: 已知f[1] = f[2] = 1,输入三个数a,b,n,求f[n] = (a*f[n-1]+b*f[n-2])%7的结果 分析: f[n-1]和f[n-2]最多为7种情况(0,1,2,3,4,5,6),则它们的组合最多为49,即周期为49. 代码如下: #include <iostream> #include <cstdio> #include <cstring> #include <fstream> #include <ctime>…
数位DP.... F(x) Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 750    Accepted Submission(s): 286 Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weig…
给一个数A (十进制表示形式为AnAn-1An-2 ... A2A1,定义函数 F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1,给一个B,求B以内的i,满足F(i)<=F(A) Sample Input 3 0 100 1 10 5 100   Sample Output Case #1: 1 Case #2: 2 Case #3: 13   一开始状态s设置的是前面位数的和,但是这样每次dp对应的值都不同,需要重新清空,浪费了很多时…
打表找规律: 当n为质数是,GCD(n)=n; 当n为质数k的q次方时,GCD(n)=k; 其他情况,GCD(n)=1. 代码如下: #include<iostream> #include<cstdlib> #include<stdio.h> #define ll long long #define M 1000001 using namespace std; ll a[M]; ],cnt; bool f[M]; int fac(int n) { ;i<cnt&a…
题目大意:f[n]-n^3=f[n-2]-(n-1)^3 (n >=3),f[1]=1,f[2]=7,求f[n]. 题目思路:将n^3移到到等式右边化简的到:f[n]=f[n-2]+3n*(n-1)+1: 因为第n项与第n-2项有关,所以知道了f[1]与f[2]的值可以分奇偶打下表,找到循环节为4018. #include<cstdio> #include<stdio.h> #include<cstdlib> #include<cmath> #incl…
思路: dp[pos][pre]代表长度为pos的不大于pre的个数 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<queue> #include<set> #include<vector> #include<map> #include<stack> #include<cmath&…
通过这个题目更加深入了解到了数位dp在记忆化搜索的过程中就是实现了没有限制条件的n位数的状态复用. #include<bits/stdc++.h> using namespace std; ]; ]; ][]; int A; int F(int x) { ]; ; ; do{ a[cnt]=x%; x/=; cnt++; }while (x); ;i>=;i--) { ret=ret*+a[i]; } return ret; } int dfs(int pos,int preok,int…
Giving the N, can you tell me the answer of F(N)? Input Each test case contains a single integer N(1<=N<=10^9). The input is terminated by a set starting with N = 0. This set should not be processed. Output For each test case, output on a line the v…
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gcd(n). Gcd(n)=gcd(C[n][1],C[n][2],--,C[n][n-1]) C[n][k] means the number of way to choose k things from n some things. gcd(a,b) means the greatest common di…
数位dp题:也是我做的第一个数位dp的题目: 感觉数位dp的模板性很强啊,思想都差不太多! 有几个写的很好的参考资料: 推荐一下: 数位计数问题解法研究 浅谈数位类统计问题 我的代码: #include<cstdio> #include<cstring> #define maxn 16 #define ll long long using namespace std; ]; int d[maxn],sum; ll dfs(int w,int he,bool flag) { ); ;…
给定一个图,要求选一个点作为起点,然后经过每条边一次,然后把访问过的点异或起来(访问一次就异或一次),然后求最大值. 首先为什么会有最大值这样的分类?就是因为你开始点选择不同,欧拉回路的结果不同,因为是回路,所以你的开始点就会被访问多一次,所以如果是欧拉回路的话,还需要O(n)扫一次,枚举每个点作为起点. 欧拉通路的话,结果是固定的,因为只能从奇数度小的那个点作为起点,奇数度大的那个点作为终点. 关于点的访问次数:anstime  = Degree[i] / 2; //如果是奇数的,还要加上一.…