HDU 4352 xhxj's Lis (Digital DP)

Source: Internet
Author: User
Tags dota
Xhxj's lis Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others) Total submission (s): 755 accepted submission (s): 289

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 your 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 wocould 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 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 wocould say: "Why do not you go to Improve Your Programming Skill ". when she has es sincere compliments from others, she wocould 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 holobby of xhxj is YY (speculation) some magical problems to discover the special properties. for example, when she see a number, she wowould 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 s Ingle 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 to handle 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.
Inputfirst a integer T (t <= 10000), then t lines follow, every line has three positive integer L, R, K .(
0 <L <= r <263-1 and 1 <= k <= 10 ).
Outputfor 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
1123 321 2
 
Sample output
Case #1: 139 
 
Author [email protected]
Source2012 multi-university training contest 6
Define the value of a number as a string. The length of his longest ascending subsequence is his value, evaluate the number of values equal to k in a certain range.

The idea comes from silver _ bullet.
Idea: Digital DP, first recall the nlogn solution of LIS. We use DP [Len] to record the size of the last number when the LIS length is Len, and then constantly update these values, make every value as small as possible. For example, if my current lis is 1 2 4 6 and the next number is 3, we need to update it to 1 2 3 6, make the preceding number as small as possible, so that more opportunities can be added to the subsequent number.
Because there are only 10 numbers, we can compress the status to record whether each number exists in the current Lis. DP [I] [J] [k]: The number of digits is K. Enumerate the current BIT for transfer. Note that the leading 0 and whether there is an upper bound mark. K is not the length of LIS. The length of a State lis is certain, but the result of a state is different for different Lis lengths, therefore, k is the length of the ascending subsequence.
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # define maxn 205 # define maxn 100005 # define mod 100000000 # define INF 0x3f3f3f # define PI ACOs (-1.0) # define EPS 1e-6typedef long ll; using namespace STD; ll n, m, ANS, TOT, le, RI, K; ll dig [20], DP [20] [1 <11] [11]; ll getsta Te (ll s, ll U, ll & XX) // status transfer {ll I, SS; for (I = u; I <10; I ++) {If (S & (1 <I) break;} if (I <10) {Ss = s ^ (1 <I ); ss = SS ^ (1 <u) ;}else {XX ++; SS = s ^ (1 <u) ;}return SS ;}ll DFS (LL POs, ll s, ll Len, ll flg, ll lead) // the upper bound of the LIS length in the current bit Lis status indicates the leading 0 Sign {If (Pos = 0) {If (LEN = k) return 1; return 0;} If (! Flg & DP [POS] [s] [k]! =-1) return DP [POS] [s] [k]; ll I, j, T, Ed, Res = 0; If (flg) Ed = dig [POS]; else ED = 9; for (I = 0; I <= Ed; I ++) {ll SS, nlen = Len; if (lead = 0 & I = 0) Ss = 0; else Ss = getstate (S, I, nlen); t = DFS (pos-1, SS, nlen, flg & I = ed, lead | I! = 0); Res + = T;} If (! Flg) DP [POS] [s] [k] = res; return res;} ll solve (ll x) {ll I, j, t = x; Tot = 0; while (t) {dig [++ tot] = T % 10; T/= 10;} ll res = DFS (TOT,); Return res ;} int main () {ll I, j, T, test = 0; memset (DP,-1, sizeof (DP); scanf ("% i64d", & T ); while (t --) {scanf ("% i64d % i64d % i64d", & Le, & Ri, & K); ans = solve (RI)-solve (le-1 ); printf ("case # % i64d: % i64d \ n", ++ test, ANS);} return 0;}/* 101 20 11 20 2 */





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.