hdu 4352 统计数字数位上最长上升子序列长度为k的个数
2013-05-21 19:25
417 查看
题意:
1245 这个数属于上升长度为4的数字,1213这个数字属于上升长度为3的数字。
统计区间[l,r]中上升长度为k的数字个数。
State 状态压缩,表示最长上升的序列用到的数字有哪些
View Code
1245 这个数属于上升长度为4的数字,1213这个数字属于上升长度为3的数字。
统计区间[l,r]中上升长度为k的数字个数。
State 状态压缩,表示最长上升的序列用到的数字有哪些
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> typedef long long LL; int const N = 22; int const M = 1030; int bit ,ln,pow2[11],k; LL dp [M][20]; void pre() { pow2[0]=1; for(int i=1;i<=10;i++)pow2[i]=(pow2[i-1]<<1); } LL getsum1(int t,int limit,int len,int state) { if(!t)return (len==k); if(!limit&&dp[t][state][k]!=-1)return dp[t][state][k]; int up=(limit?bit[t]:9); LL ans=0; for(int i=0;i<=up;i++) { if(state||i) { if(pow2[i]>state) { ans+=getsum1(t-1,limit&&i==up,len+1,state|pow2[i]); } if(pow2[i]&state) { ans+=getsum1(t-1,limit&&i==up,len,state); } else { for(int j=i+1;j<=9;j++) { if(state&pow2[j]) { ans+=getsum1(t-1,limit&&i==up,len,state^pow2[j]|pow2[i]); break; } } } } else { ans+=getsum1(t-1,limit&&i==up,0,0); } } if(!limit)dp[t][state][k]=ans; return ans; } LL getsum2(LL n) { if(n==0)return 0; for(ln=0;n;bit[++ln]=n%10,n/=10); return getsum1(ln,1,0,0); } int main() { pre(); memset(dp,-1,sizeof(dp)); int T,t=0; k=2; scanf("%d",&T); while(T--) { LL l,r; scanf("%I64d %I64d",&l,&r); scanf("%d",&k); l--; printf("Case #%d: %I64d\n",++t,getsum2(r)-getsum2(l)); } return 0; }
View Code
相关文章推荐
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列的长度)
- HDU 1025 Constructing Roads In JGShining's Kingdom(最长上升子序列的长度)
- HDU 1160 FatMouse's Speed(最长上升子序列长度及其路径)
- hdu 4352 数位dp(最长上升子序列的长度为k的个数)
- HDU-1257 最少拦截系统 贪心/DP 最长上升子序列的长度==最长不上升子序列的个数?
- HDU 5748 最长上升子序列的长度nlogn(固定尾部)
- 最长上升子序列(LIS)长度的O(nlogn)算法
- hdu 5256 序列变换(最长上升子序列&&二分)
- HDU-1950-Bridging signals【最长上升子序列(LIS)长度的O(nlogn)算法】
- 求最长上升子序列的长度
- HDU_3998_Sequence(最长上升子序列 + 网络流)
- HDU 3998 Sequence (最长上升子序列 + 最大流)
- 最长上升子序列长度及其个数
- POJ 1631 HDU 1950(最长上升子序列问题)
- 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero
- 最长上升子序列 HDU 1025 Constructing Roads In JGShining's Kingdom
- 三维最长上升子序列问题——HDU 1069 Monkey and Banana
- DP 动态规划 Problem B 1002 求最长上升子序列的长度
- [HDU 1423] Greatest 最长上升公共子序列
- 【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!