hdu4352 XHXJ's LIS

2024-05-14 12:08
文章标签 lis xhxj hdu4352

本文主要是介绍hdu4352 XHXJ's LIS,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

XHXJ's LIS

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 591 Accepted Submission(s): 241


Problem Description
#define xhxj (Xin Hang senior sister(学姐))
If you do not know xhxj, then carefully reading the entire description is very important.
As the strongest fighting force in UESTC, xhxj grew up in Jintang, a border town of Chengdu.
Like many god cattles, xhxj has a legendary life:
2010.04, had not yet begun to learn the algorithm, xhxj won the second prize in the university contest. And in this fall, xhxj got one gold medal and one silver medal of regional contest. In the next year's summer, xhxj was invited to Beijing to attend the astar onsite. A few months later, xhxj got two gold medals and was also qualified for world's final. However, xhxj was defeated by zhymaoiing in the competition that determined who would go to the world's final(there is only one team for every university to send to the world's final) .Now, xhxj is much more stronger than ever,and she will go to the dreaming country to compete in TCO final.
As you see, xhxj always keeps a short hair(reasons unknown), so she looks like a boy( I will not tell you she is actually a lovely girl), wearing yellow T-shirt. When she is not talking, her round face feels very lovely, attracting others to touch her face gently。Unlike God Luo's, another UESTC god cattle who has cool and noble charm, xhxj is quite approachable, lively, clever. On the other hand,xhxj is very sensitive to the beautiful properties, "this problem has a very good properties",she always said that after ACing a very hard problem. She often helps in finding solutions, even though she is not good at the problems of that type.
Xhxj loves many games such as,Dota, ocg, mahjong, Starcraft 2, Diablo 3.etc,if you can beat her in any game above, you will get her admire and become a god cattle. She is very concerned with her younger schoolfellows, if she saw someone on a DOTA platform, she would say: "Why do not you go to improve your programming skill". When she receives sincere compliments from others, she would say modestly: "Please don’t flatter at me.(Please don't black)."As she will graduate after no more than one year, xhxj also wants to fall in love. However, the man in her dreams has not yet appeared, so she now prefers girls.
Another hobby of xhxj is yy(speculation) some magical problems to discover the special properties. For example, when she see a number, she would think whether the digits of a number are strictly increasing. If you consider the number as a string and can get a longest strictly increasing subsequence the length of which is equal to k, the power of this number is k.. It is very simple to determine a single number’s power, but is it also easy to solve this problem with the numbers within an interval? xhxj has a little tired,she want a god cattle to help her solve this problem,the problem is: Determine how many numbers have the power value k in [L,R] in O(1)time.
For the first one to solve this problem,xhxj will upgrade 20 favorability rate。

Input
First a integer T(T<=10000),then T lines follow, every line has three positive integer L,R,K.(
0<L<=R<2 63-1 and 1<=K<=10).

Output
For each query, print "Case #t: ans" in a line, in which t is the number of the test case starting from 1 and ans is the answer.

Sample Input
  
1 123 321 2

Sample Output
  
Case #1: 139
先求lis,因为只有9个数字,所以可以用状压,这样更快,求法还是和lis是一样的,其次,就是一个数位dp了!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 100
int k,pri[M];
__int64 dp[M][15][1<<10][2];
int get(int x){int ans=0;for(int i=0;i<10;i++){if((1<<i)&x)ans++;}return ans;
}
int gett(int t,int i){for(int j=i;j<10;j++){if(t&(1<<j))return (t^(1<<j))|(1<<i);}return t|(1<<i);
}
__int64 dfs(int pos,int t,int one,int flag){if(pos==0)return get(t)==k;if(!flag&&dp[pos][k][t][one]!=-1)return dp[pos][k][t][one];int u=flag?pri[pos]:9;__int64 ans=0;for(int i=0;i<=u;i++)ans+=dfs(pos-1,one||i?gett(t,i):0,one||i,flag&&i==u);return flag?ans:dp[pos][k][t][one]=ans;
}
__int64 solve(__int64 x){int cnt=0;while(x){pri[++cnt]=x%10;x/=10;}return dfs(cnt,0,0,1);
}
int main()
{int tcase,tt=1;__int64 l,r;scanf("%d",&tcase);memset(dp,-1,sizeof(dp));while(tcase--){scanf("%I64d%I64d%d",&l,&r,&k);printf("Case #%d: %I64d\n",tt++,solve(r)-solve(l-1));}return 0;
}


这篇关于hdu4352 XHXJ's LIS的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/988708

相关文章

【UVA】10534 - Wavio Sequence(LIS最长上升子序列)

这题一看10000的数据量就知道必须用nlog(n)的时间复杂度。 所以特意去看了最长上升子序列的nlog(n)的算法。 如果有2个位置,该位置上的元素为A[i]和A[j],并且他们满足以下条件: 1.dp[i] = dp[j]    (dp[x]代表以x结尾的最长上升子序列长度) 2.A[i] < A[j] 3.i < j 那么毫无疑问,选择dp[i] 一定优于选择dp[j] 那么

医院检验系统LIS源码,LIS系统的定义、功能结构以及样本管理的操作流程

本文将对医院检验系统LIS进行介绍,包括LIS系统的定义、功能结构以及样本管理的操作流程方面。 LIS系统定义 LIS系统(Laboratory Information System)是一种专门为临床检验实验室开发的信息管理系统,其主要功能包括实验室信息管理、样本管理、检验结果管理、质量控制管理、数据分析等。其主要作用是管理医院实验室的各项业务,包括样本采集、检验、结果录入和报告生成等。Li

LCS转为LIS

(1) 先将所有数列排序。     第一维由小到大,当第一维相等时,第二维由大到小。   (排序规则亦可改成以第二个维度为主,最后则是找第一个维度的1DLIS。)       a     a    a     b     b    a     a     a    c     d   (0,6) (0,3) (0,2) (1,4) (1,1)(2,6) (2,3) (2,2) (3,5) (4,

uva10534(DP之LIS的应用 )

题意:在给出的序列中找到一个长度为奇数的序列,且序列前半段严格单调递增,后半段严格单调递减。 解答:进行两次LIS,一次正向,一次逆向,LIS选用Nlogn的算法 /*Solve:*/#include<iostream>#include<algorithm>#include<map>#include<cstdio>#include<cstdlib>#include<vector>

HDU 5748 (Bellovin LIS)

题目连接 nlogn求一下LIS 就好了 #include<cstdio>#include<algorithm>#include<iostream>using namespace std;#define cl(a,b) memset(a,b,sizeof(a))#define LL long long#define pb push_back#define gcd __gcd#de

F. LIS on Tree 树上根路径LIS

1 关于lower_bound // 12345 查4 应该放在4 。而不是5的位置。。所以不是uppper。 //如果1235 查4 。可以优化5 。 2 关于 ans[u] = max(j, ans[p]); 维护一个max 一定从(premax,cur)中选出来的。 3 关于 memset(st, 0x3f, sizeof st); 这个和st + 1, st + n + 1 。。我们二分选

POJ 2533 LIS N2

状态转移方程  dp[i]=max(dp[i],dp[j]+1); dp[i]为以第i个数结尾的能得到的最长的上升子序列。1<=j<i。 这个题目注意a[i]可能为0,因此要注意初始化a[0]=-1; http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MSMemory Limit: 6

HDU 5532 Almost Sorted Array (2015ACM/ICPC长春LIS)

【题目链接】:click here~~ 【题目描述】: Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 272    Accepted Submission(s): 132

LIS(最长递增子序列)和LCS(最长公共子序列)的总结

LIS(最长递增子序列)和LCS(最长公共子序列)的总结 最长公共子序列(LCS):O(n^2) 两个for循环让两个字符串按位的匹配:i in range(1, len1) j in range(1, len2) s1[i - 1] == s2[j - 1], dp[i][j] = dp[i - 1][j -1] + 1; s1[i - 1] != s2[j - 1], dp[

UVA 10354 nlogn LIS

nlogn的最长上升子序列(原理)。这是第一个trick。 第二个,要左边和右边的相同,枚举每一个点作为最高点时的情况。两边取较小的那个再乘以2。 #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define MS(x) memset(x,0,sizeof(x))int up[