hdu4352 XHXJ's LIS
这个题最不好想到的是状态的保存,也没有几亿的数组让你开,怎么保存前面出现了哪些数字。
题意让你求最长上升子序列的长度为k的数字的数目,可以是不连续的,可以保留一个状态栈,栈顶部依次更新,再保证长度最大的情况下使栈顶元素最小,这样就能保证下次加进来的元素有可能会使长度增加。这个状态就用2进制来表示,1的个数就是最后的长度。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][<<][];
int dd[],k,d[];
LL dfs(int i,int e,int tt)
{
if(i==-)
{
int num = ;
for(int g = ;g <= ;g++)
if((<<g)&tt)
num++;
return num==k;
}
if(!e&&dp[i][tt][k]!=-) return dp[i][tt][k];
int mk = e?d[i]:;
LL ans = ;
int j;
for(j=;j <= mk ; j++)
{
int te = tt;
for(int g = j; g <= ; g++)
{
if((<<g)&tt)
{
te-=(<<g);
break;
}
}
if(tt||j!=)
te|=(<<j);
ans+=dfs(i-,e&&j==mk,te);
}
return e?ans:dp[i][tt][k] = ans;
}
LL cal(LL x)
{
int dd[];
memset(dd,,sizeof(dd));
int g = ;
while(x)
{
d[g++] = x%;
x/=;
}
return dfs(g-,,);
}
int main()
{
int t;
LL l,r;
cin>>t;
memset(dp,-,sizeof(dp));
int kk = ;
while(t--)
{
cin>>l>>r>>k;
printf("Case #%d: ",++kk);
cout<<cal(r)-cal(l-)<<endl;
}
return ;
}
hdu4352 XHXJ's LIS的更多相关文章
- hdu4352 XHXJ's LIS(数位dp)
题目传送门 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU4352 XHXJ's LIS(LIS 状压)
题意 题目链接 Sol 刚开始的思路是\(f[i][j]\)表示到第\(i\)位,LIS长度为\(j\)的方案. 然而发现根本不能转移,除非知道了之前的状态然后重新dp一遍.. 题解,,,挺暴力的把, ...
- hdu4352 XHXJ's LIS(数位DP + LIS + 状态压缩)
#define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the entire ...
- hdu4352 XHXJ's LIS[数位DP套状压DP+LIS$O(nlogn)$]
统计$[L,R]$内LIS长度为$k$的数的个数,$Q \le 10000,L,R < 2^{63}-1,k \le 10$. 首先肯定是数位DP.然后考虑怎么做这个dp.如果把$k$记录到状态 ...
- HDU4352 XHXJ's LIS 题解 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 题目大意: 求区间 \([L,R]\) 范围内最长上升子序列(Longest increasin ...
- hdu4352 XHXJ's LIS (数位dp)
Problem Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then careful ...
- 【HDU 4352】 XHXJ's LIS (数位DP+状态压缩+LIS)
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
- XHXJ's LIS(数位DP)
XHXJ's LIS http://acm.hdu.edu.cn/showproblem.php?pid=4352 Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 相识从C语言开始
大家好,我是你们这学期C语言的助教吴科桥(女O(∩_∩)O),非常开心能在你们美好的大学这站与你们相遇,希望可以为你们学习C语言略尽绵薄之力. 开学第一周: 1. 希望每个同学都可以有自己的博客,我会 ...
- LeetCode Two Sum III - Data structure design
原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...
- ionic安装指定版本
npm install -g ionic@1.4.0 原文地址:http://stackoverflow.com/questions/30316994/how-to-install-specific- ...
- 循环调用MAIN
--单位转移录入declare oi_errcode integer; oc_errtext varchar2(100);begin for p in (select * from ssunitinf ...
- li ul 说明
复制代码代码如下: <div id="menu"> <ul> <li><a href="#">首页</ ...
- 关于IP地址的一个细节问题
使用ip2long()和long2ip()函数把IP地址转成整型存放进数据库而非字符型.这几乎能降低1/4的存储空间.同时可以很容易对地址进行排序和快速查找;
- Eclipse下Tomcat插件的安装
在Eclipse下安装Tomcat插件使开发,编译,发布变的相当的简单,下面就说一下安装的过程,很简单的: 1.先下载一个tomcat插件 地址:http://www.eclipsetotale.co ...
- Linux 批量改名之 rename 命令
刚学习到 rename 命令功能很强大,比win 下的 ren 厉害啊 具体看 man rename 语法: rename [ -h|-m|-V ] [ -v ] [ -n ] [ -f ] [ - ...
- maven常见错误
摘要: 1.Java-maven异常-cannot be cast to javax.servlet.Filter 报错 tomcat 启动后先将tomcat/lib目录下的jar包全部读入内存,如 ...
- C语言中执行到预编译
在Linux中,执行命令:gcc -o linux.i linux.c -E