hdu4352 XHXJ's LIS(数位dp+状压)
来源:互联网 发布:炮火兰捏脸数据 编辑:程序博客网 时间:2024/06/06 00:38
hdu4352
题目
某个数字如果把它看成序列,每一位的LIS个数是k,就是我们要找的,现在求给定范围内的这种数字的个数
思路
一开始以为只要记最大位以及长度即可,果然还是太傻太天真,正解是利用nlogn的思想,将每个数字是否出现进行状态压缩,对于枚举的新的一位x,将第一个比这个数字大的数字消去改成这个数,也就是(s^(1<
代码
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;typedef long long ll;ll dp[20][1500][15];int dig[20];ll n,m;int k;int getnew(int x,int s){ for(int i=x; i<10; i++) if(s&(1<<i)) return (s^(1<<i)|(1<<x)); return s|(1<<x);}int getnum(int a){ int ret=0; while(a) { if(a&1) ret++; a>>=1; } return ret;}ll dfs(int len,int s,int z,int lim){ if(len<0) return getnum(s)==k; if(!lim&&dp[len][s][k]!=-1) return dp[len][s][k]; int e=lim?dig[len]:9; ll ans=0; for(int st=0; st<=e; st++) { ans+=dfs(len-1,(st==0&&z==1)?0:getnew(st,s),st==0&&z==1,lim&&st==e); } if(!lim) return dp[len][s][k]=ans; return ans;}ll solve(ll u){ int len=0; while(u) { dig[len++]=u%10; u/=10; } return dfs(len-1,0,1,1);}int main(){ memset(dp,-1,sizeof(dp)); int kase=1; int T; scanf("%d",&T); while(T--) { scanf("%I64d %I64d %d",&n,&m,&k); printf("Case #%d: %I64d\n",kase++,solve(m)-solve(n-1)); } return 0;}
0 0
- hdu4352 XHXJ's LIS(数位dp+状压)
- hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)
- XHXJ's LIS HDU4352(数位DP)
- hdu4352 XHXJ's LIS 数位DP
- hdu4352 XHXJ's LIS (数位dp)
- hdu4352 XHXJ's LIS(数位Dp)
- 【HDU4352】XHXJ's LIS 数位DP
- hdu4352——XHXJ's LIS(数位DP+状压)
- 【HDU4352/ZCMU1781】XHXJ's LIS(数位DP)
- hdu4352---XHXJ's LIS(状态压缩数位dp)
- hdu4352 XHXJ's LIS 数位DP+状态压缩
- HDU4352 XHXJ's LIS 数位DP+状态压缩
- hdu4352 XHXJ's LIS
- hdu4352 XHXJ's LIS
- 【HDU4352】 XHXJ's LIS
- XHXJ's LIS---数位DP
- HDU4352 lis+状压+数位dp
- HDU_4352 _ XHXJ's LIS (数位Dp+LIS + 状压)
- Libevent源码分析-----event-config.h指明所在系统的环境
- js 原型和原型链详解,总结的很好,值得学习
- POJ 3180 The Cow Prom 求强连通分量 .
- 20160823群赛round6
- 用 GRUB 引导自己的操作系统
- hdu4352 XHXJ's LIS(数位dp+状压)
- 使用QM的外部工具功能编译代码
- nginx + lua环境搭建
- c++线程
- Libevent源码分析-----日志和错误处理
- centos7 安装 openvpn2.2.2 过程
- 大数据索引
- 页面的跳转技巧--setViewControllers
- Unity学习 第一章 环境搭建熟悉 unity