HDU 6156 Palindrome Function】的更多相关文章

普通的数位DP计算回文串个数 /* HDU 6156 - Palindrome Function [ 数位DP ] | 2017 中国大学生程序设计竞赛 - 网络选拔赛 2-36进制下回文串个数 */ #include <bits/stdc++.h> using namespace std; #define LL long long int t, L, R, l, r, base; int dig[40], tmp[40]; LL dp[40][40][40][2]; LL DFS(int p…
http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:$f(n,k)$表示判断n在k进制下是否是回文串,如果是,则返回k,如果不是,则返回1.现在要计算$\sum_{i=L}^{R}\sum_{j=l}^{r}f(i,j)$. 思路:因为我不会数位dp,所以我直接模拟做了一发,写得十分繁琐... 先是将数转换成k进制,然后去计算出它的前一半的数,只要小于该数那都是成立的 ,比如说现在前面的数为985,那么1~984的数都是满足的,绝对不会超. 思路大…
http://acm.hdu.edu.cn/showproblem.php?pid=6156 [AC] #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ]; int L,R,l,r; ll query(int x,int k) { ) ; ; int cp=x; while(cp) { num[cnt++]=cp%k; cp/=k; } ,tot=; ;i<cnt;i++) { tot+=base-…
思路: 数位dp的操作是dfs+记忆化,我们dp开四维:位置,长度,进制,是否回文.然后每次暴搜记录下每个位置的数字是什么,搜到对称轴另一边需要检查是否符合回文. 终于把友谊赛的题目都补完了...没做出来的都是学过的,做出来的都是没学过骚操作过的...学以不致用... 代码: #include<cstdio> #include<set> #include<stack> #include<cstring> #include<algorithm> #…
Palindrome Function As we all know,a palindrome number is the number which reads the same backward as forward,such as 666 or 747.Some numbers are not the palindrome numbers in decimal form,but in other base,they may become the palindrome number.Like…
题意:输入一个字符串,至少插入几个字符可以变成回文串(左右对称的字符串) 分析:f[x][y]代表x与y个字符间至少插入f[x][y]个字符可以变成回文串,可以利用动态规划的思想,求解 状态转化方程: f[x][y]=0  初始化 f[x][y]=f[x+1][y-1]     s[x]==s[y]时 f[x][y]=MIN ( f[x+1][y] , f[x][y-1] )+1    s[x] != s[y]时 代码展示 一开始没有将算的的数据存放到数组中,使得有些数据重复计算好多次,TLE…
Palindrome Function Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 863    Accepted Submission(s): 476 Problem Description As we all know,a palindrome number is the number which reads the same…
Palindrome Function Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total Submission(s): 559    Accepted Submission(s): 299 Problem Description As we all know,a palindrome number is the number which reads the same…
/* HDU 6050 - Funny Function [ 公式推导,矩阵快速幂 ] 题意: F(1,1) = F(1, 2) = 1 F(1,i) = F(1, i-1) + 2 * F(1, i-2) , i >= 3 F(i, j) = ∑ F(i-1, j) , k∈[j, j+N-1] 给定 N, M < 2^63, 求 F(M,1) 分析: ∵ F(2,1) = F(1,1) + F(1,2) + ... + F(1,N) F(2,2) = F(2,1) + F(1,N+1) -…
要求m-n内在l-r进制下的是回文数的总个数. dp[进制][从第j为开始][目前到达第k位] = 总的方案数 dfs枚举目前的到达的位置,这个数开始的位置,进制,前导零,限制条件,然后枚举的时候如果我现在是总的数的前一半,那么我就可以随意枚举,如果我已经到这个数的后一半了,那么我枚举的数字应该要满足和前面一半的这个位置对应的数,否则的话就是不满足条件的回文数,用这个数开始的位置为0来表示这个数不满足条件或者说我枚举的这个数全部都是零.然后算出这个区间内的回文数,要求sumf(i, j), 那么…