hdu 6156 Palindrome Function(数位dp&&其他)
来源:互联网 发布:linux 客户端工具 编辑:程序博客网 时间:2024/06/06 03:29
我的数位dp加上输入输出外挂还是超时了,罪过罪过。不过对于我理解数位dp 还是有帮助的
#include<bits/stdc++.h>using namespace std;typedef long long ll;int bit[38],temp[38];ll dp[38][38][38]; int p; int Scan(){ // 输入外挂 int res = 0, flag = 0; char ch; if ((ch = getchar()) == '-') { flag = 1; } else if(ch >= '0' && ch <= '9') { res = ch - '0'; } while ((ch = getchar()) >= '0' && ch <= '9') { res = res * 10 + (ch - '0'); } return flag ? -res : res;}void Out(int a){ // 输出外挂 if (a < 0) { putchar('-'); a = -a; } if (a >= 10) { Out(a / 10); } putchar(a % 10 + '0');}ll dfs(int len,int pos,int st,int lim)//st判断是否一直为0,lim为上界{ if(lim==0&&dp[p][len][pos]!=-1&&!st)return dp[p][len][pos]; if(pos<0) { return 1; } int num=lim?bit[pos]:p-1; ll ans=0; for(int i=0;i<=num;i++) { temp[i]=i; if(st) ans+=dfs(len-(st&&i==0),pos-1,i==0,lim&&i==num); else { if((pos<(len+1)/2 && i==temp[len-pos]) || pos>=(len+1)/2) ans+=dfs(len,pos-1,0,lim&&i==num); } } if(!lim&&!st)dp[p][len][pos]=ans; return ans;}ll solve(int x){ int len=0; while(x) { bit[len++]=x%10; x/=10; } return dfs(len-1,len-1,1,1);}int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int t,cas=1; ll ans; scanf("%d",&t); while(t--) { int l,r,x,y;l=Scan();r=Scan();x=Scan();y=Scan(); ans=0; memset(dp,-1,sizeof(dp)); for(int i=x;i<=y;i++) { p=i; ans+=(solve(r)-solve(l-1))*(i-1); } printf("Case #%d: ", cas++); Out(ans+(ll)(r-l+1)*(y-x+1)); puts(""); } return 0;}
阅读全文
0 0
- hdu 6156 Palindrome Function(数位dp&&其他)
- hdu 6156 Palindrome Function 数位DP
- HDU 6156 Palindrome Function 经典数位DP
- HDU 6156 Palindrome Function 数位DP
- Hdu 6156 Palindrome Function【数位Dp】
- HDU 6156 Palindrome Function(数位DP)
- HDU-6156 Palindrome Function(数位DP)
- HDU 6156(Palindrome Function-数位dp)
- HDU 6156 Palindrome Function (数位dp)
- HDU 6156 Palindrome Function【数位dp】
- hdu 6156 Palindrome Function(数位dp)
- hdu 6156 palindrome function #数位dp 3
- hdu 6156 Palindrome Function【数位dp求回文数】
- HDU6156 Palindrome Function[数位DP]
- hdu6156 Palindrome Function数位dp
- hdu6156 Palindrome Function 数位dp
- HDU 6156 2016ICPC网络赛 G: Palindrome Function(数位DP)
- 【HDU6156】Palindrome Function(数位DP+回文串)
- git基本命令
- react-native的textInput学习中宽自动变小的问题
- spring整合hibernate的初级使用
- bzoj 3890: [Usaco2015 Jan]Meeting Time bfs
- AJAX的使用
- hdu 6156 Palindrome Function(数位dp&&其他)
- Keras学习笔记---保存model文件和载入model文件
- 位运算
- memset的妙用
- mybaties入门
- HDU 1272 小希的迷宫 并查集
- Redis的相关命令
- hdu 1385 Minimum Transport Cost
- 155. Min Stack。