【HDU4352】 XHXJ's LIS
来源:互联网 发布:大数据 a股 编辑:程序博客网 时间:2024/06/05 02:14
Problem
http://acm.hdu.edu.cn/showproblem.php?pid=4352
Solution
数位DP+LIS+状压
解题前奏:nlogn LIS
具体:记录前len位的LIS情况,可以预处理sta+i后的newsta,然后DFS,DP写超时(10000组)
CODE
/* * @key word:digit DP * @tesed on:HDU4352 62ms * @Author: lhq * @Date: 2017-08-15 12:30:13 * @Last Modified by: lhq * @Last Modified time: 2017-08-15 12:30:36 */#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define ll long longint change[1<<10][10],one[1<<10],a[20],K;ll dp[20][1<<10][11];ll dfs(int len,int sta,bool limit){ if (len==0) return one[sta]==K?1:0; if (!limit && dp[len][sta][K]!=-1) return dp[len][sta][K]; int up=limit?a[len]:9; ll ans=0; for (int i=0;i<=up;i++) ans+=dfs(len-1,change[sta][i],limit && i==up); if (!limit) dp[len][sta][K]=ans; return ans;}ll solve(ll x){ int len=0; while (x) { a[++len]=x%10; x/=10; } return dfs(len,0,true);}void prepare(){ memset(dp,-1,sizeof(dp)); for (int i=0;i<1<<10;i++) for (int j=0;j<=9;j++) { if (i==0 && j==0) continue; int p=i; for (int k=j;k<=9;k++) if (p & (1<<k)) {p^=1<<k; break;} change[i][j]=p^(1<<j); } for (int i=0;i<1<<10;i++) for (int j=0;j<=9;j++) if (i & 1<<j) one[i]++;}int main(){ prepare(); int T; cin>>T; for (int i=1;i<=T;i++) { ll l,r; scanf("%lld%lld%d",&l,&r,&K); printf("Case #%d: %lld\n",i,solve(r)-solve(l-1)); } return 0;}
阅读全文
0 0
- hdu4352 XHXJ's LIS
- hdu4352 XHXJ's LIS
- 【HDU4352】 XHXJ's 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 + LIS + 状态压缩)
- 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+状压)
- HDU 4352 XHXJ's LIS
- XHXJ's LIS---数位DP
- HDU-4352 XHXJ's LIS
- apk反编译
- 【自考】数据库系统原理(第二遍)
- 1059: 最高分
- Ruby操作MongoDB(进阶七)-排序规则Collations
- 关于写博客的这点事
- 【HDU4352】 XHXJ's LIS
- Unity 打包 SDK 问题合集
- Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)
- 通过文件的拷贝例子,来详解文件资源的正确关闭的两种方法
- java的三大特性
- Ruby操作MongoDB(进阶八)-聚合操作Aggregation
- POJ1661 help Jimmy(动态规划)已ac,附带测试数据
- Mybatis源码分析-StatementHandler
- JavaScript基础Dom 个人笔记