HDU 4352 XHXJ's LIS
来源:互联网 发布:javascript源码大全 编辑:程序博客网 时间:2024/06/05 19:40
数位DP,以dp[index][sta][k]来记录搜索到当前层时,最长序列的状态为sta,要求的是长度为k的序列的个数。状态sta中1的个数即是当前这个数的最长上子升序列的长度,
这个状态的求法和nlogn求最长上升子序列的求法是一样的。
#include <cstdio>#include <cstring>#include <string>#include <iostream>#include <map>#include <vector>#include <cmath>#include <stack>#include <queue>#include <cstdlib>#include <algorithm>using namespace std;typedef __int64 int64;typedef long long ll;#define M 100005#define N 1000005#define max_inf 0x7f7f7f7f#define min_inf 0x80808080#define mod 1000000007int k;int dig[30];int64 dp[30][1<<11][11];int Getlen (int sta)//求出最长上升子序列的长度{int ret = 0;while (sta){ret += (sta&1);sta >>= 1;}return ret;}int Getnew(int x , int sta)//更新当前数的最长上升子序列的状态{int i;for (i = x ; i <= 9 ; i++)if ((sta & (1<<i)))return (sta-(1<<i))|(1<<x);return sta|(1<<x);}int64 Dfs(int index , int fg , int sta , int lim)//fg标记前面是否出现过非零位{if (!index)return Getlen(sta) == k;if (!lim && dp[index][sta][k] != -1)return dp[index][sta][k];int i , up = lim ? dig[index] : 9;int64 ret = 0;for (i = 0 ; i <= up ; i++){ret += Dfs(index-1 , fg||i!=0 , (!fg&&i==0) ? 0 : Getnew(i,sta) , lim&&i==up);}if (!lim)dp[index][sta][k] = ret;return ret;}int64 Solve(int64 num){int len = 0;while (num){dig[++len] = num%10;num /= 10;}return Dfs(len , 0 , 0 , 1);}int main(){int t , tcase = 1;int64 l , r;scanf("%d",&t);memset(dp , -1 , sizeof dp);while (t--){scanf("%I64d%I64d%d",&l,&r,&k);printf("Case #%d: %I64d\n",tcase++,Solve(r)-Solve(l-1));}return 0;}
- HDU 4352 XHXJ's LIS
- HDU-4352 XHXJ's LIS
- hdu 4352 XHXJ's LIS
- HDU 4352 XHXJ's LIS
- HDU 4352 XHXJ's LIS
- hdu 4352 XHXJ's LIS
- HDU 4352 XHXJ's LIS
- 【HDU】4352 XHXJ's LIS 数位DP
- 【数位DP】【hdu 4352】XHXJ's LIS
- HDU 4352 XHXJ's LIS 数位dp
- HDU 4352 XHXJ's LIS(数位DP)
- hdu 4352 XHXJ's LIS(数位dp)
- HDU 4352 XHXJ's LIS【数位DP】
- hdu 4352 XHXJ's LIS(LIS+数位DP,5级)
- 数位dp+LIS+状态压缩-hdu-4352-XHXJ's LIS
- HDU 4352 XHXJ's LIS 数位dp+lis
- HDOJ 4352 XHXJ's LIS
- hdu 4352 XHXJ's LIS --- 数位dp 状态压缩
- 【利用javamail和POP3、SMPT协议实现邮件的收发】
- 扩展logback DBApender 自定义录入字段
- CentOS-6.4安装MySQL 5.6.10
- PCI串口
- CheckStyle及其配置的详细解释
- HDU 4352 XHXJ's LIS
- Sqlmap注入技巧收集
- 【"六拍"项目】,你拍过吗?
- 多用户数据库环境下DB2事务及锁浅谈
- QString 与中文问题
- 获取WebView加载HTML时网页中的内容 获取页面元素
- Android上构建基于httpclient的网络连接池
- zigbee组网调用
- 把html做成jsp并抽取其中的css样式和js 样式和js都要求分包