hdu 4352 XHXJ's LIS 数位DP
数位DP!
dp[i][j][k]:第i位数,状态为j,长度为k
代码如下:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
using namespace std;
ll dp[][][];
int bit[],k;
int Getlen (int sta)//求出最长上升子序列的长度
{
int ret = ;
while (sta)
{
ret += (sta&);
sta >>= ;
}
return ret;
} int Getnew(int x , int sta)//更新当前数的最长上升子序列的状态
{
int i;
for (i = x ; i <= ; i++)
if ((sta & (<<i)))
return (sta-(<<i))|(<<x);
return sta|(<<x);
}
ll dfs(int pos,int s,bool z,bool f)
{
if(pos==-) return Getlen(s)==k;
if(!f&&dp[pos][s][k]!=-) return dp[pos][s][k];
ll ans=;
int e=f?bit[pos]:;
for(int i=;i<=e;i++){
ans+=dfs(pos-,(z&&i==)?:Getnew(i,s),z&&i==,f&&i==e);
}
if(!f&&dp[pos][s][k]==-) dp[pos][s][k]=ans;
return ans;
}
ll cal(ll n)
{
int m=;
while(n){
bit[m++]=n%;
n/=;
}
return dfs(m-,,,);
}
int main()
{
int t,i,j,ca=;
ll a,b;
scanf("%d",&t);
memset(dp,-,sizeof(dp));
while(t--){
scanf("%I64d%I64d%d",&a,&b,&k);
printf("Case #%d: %I64d\n",++ca,cal(b)-cal(a-));
}
return ;
}
hdu 4352 XHXJ's LIS 数位DP的更多相关文章
- HDU 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
- hdu 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- HDU.4352.XHXJ's LIS(数位DP 状压 LIS)
题目链接 \(Description\) 求\([l,r]\)中有多少个数,满足把这个数的每一位从高位到低位写下来,其LIS长度为\(k\). \(Solution\) 数位DP. 至于怎么求LIS, ...
- HDU 4352 XHXJ's LIS (数位DP+LIS+状态压缩)
题意:给定一个区间,让你求在这个区间里的满足LIS为 k 的数的数量. 析:数位DP,dp[i][j][k] 由于 k 最多是10,所以考虑是用状态压缩,表示 前 i 位,长度为 j,状态为 k的数量 ...
- $HDU$ 4352 ${XHXJ}'s LIS$ 数位$dp$
正解:数位$dp$+状压$dp$ 解题报告: 传送门! 题意大概就是港,给定$[l,r]$,求区间内满足$LIS$长度为$k$的数的数量,其中$LIS$的定义并不要求连续$QwQ$ 思路还算有新意辣$ ...
- hdu 4352 XHXJ's LIS 数位DP+最长上升子序列
题目描述 #define xhxj (Xin Hang senior sister(学姐))If you do not know xhxj, then carefully reading the en ...
- HDU 4352 - XHXJ's LIS - [数位DP][LIS问题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- HDU 4352 XHXJ's LIS ★(数位DP)
题意 求区间[L,R]内满足各位数构成的数列的最长上升子序列长度为K的数的个数. 思路 一开始的思路是枚举数位,最后判断LIS长度.但是这样的话需要全局数组存枚举的各位数字,同时dp数组的区间唯一性也 ...
- hdu 4352 XHXJ's LIS(数位dp+状压)
Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefull ...
随机推荐
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- php连接mysql报错No such file or directory
php测试文件如下: 1 2 3 4 5 6 7 8 9 10 11 <?php $con = mysql_connect("localhost","root&qu ...
- [转]SOLID开发原则-面向对象
S.O.L.I.D是面向对象设计和编程(OOD&OOP)中几个重要编码原则(Programming Priciple)的首字母缩写. SRP The Single Responsibility ...
- Jsp实现form的file和text传递(multipart/form-data)
Jsp实现form的file和text传递(multipart/form-data) 首先是form部分,因为要有<input type="file" />的类型,所以 ...
- 新手学Android
Eclipse平台下的新手Android学习记录. 1.打开一个本地的项目 在Project Explorer右键->Import->Existing Projects into Work ...
- P1231: [Usaco2008 Nov]mixup2 混乱的奶牛
这是一道状压DP,首先这道题让我意识到状态是从 1 to (1<<n)-1 的,所以当前加入的某头牛编号是从 0 to n-1 的,所以存储的时候习惯要改一下,这样子做状压DP才会顺一点吧 ...
- Indigo Studio
http://www.infragistics.com/products/indigo-studio?gclid=CIXrnav4lcQCFdclvQoduVEAnA
- SqlHelper include Transaction
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- pxe+preseed安装配置(2)
1.tftp使用独立daemon,这样不用再安装xinet, apt-get install tftp-hpa tftpd-hpa cat /etc/default/tftpd-hpa TFTP_US ...
- ORM 框架
1.Dapper 2.Entity Framework(EF) http://www.cnblogs.com/n-pei/archive/2011/09/06/2168433.html