Bzoj2431: [haoi2009] Reverse Sequence

Source: Internet
Author: User
2431: [haoi2009] Time Limit: 5 sec memory limit: 128 MB
Submit: 831 solved: 473
[Submit] [Status] Description

For a series {ai}, If I <j and AI> AJ exists, we call AI and AJ a pair of reverse logarithm. If any ~ A series composed of natural numbers can easily find the number of reverse logarithm numbers. So how many natural numbers are there in a series with K in the reverse order?

 

Input

The first behavior is two integers n, k.

 

 

 

Output

Write an integer to indicate the number of qualified series. Because this number may be large, you only need to output the result after the remainder of the number pair 10000.

 

 

 

 

Sample input

4 1


Sample output sample output

3

Example:

The reverse logarithm of the following three series is 1; they are 1 2 4 3; 1 3 2 4; 2 1 3 4;



Test data range

30% of Data n <= 12

100% of Data n <= 1000, k <= 1000 hint Source

Day1

Question: F [I, j] is used to represent the total number of I, and the number of pairs in the reverse order is J. The recursive formula F [I, j] = Sigma {f [I-1, j-K]} 0 = <k <= I-1 in the use of continuous and optimization, that is, using a temporary variable to store the value on the right of the equation, each time to the next J, delete the code that is out of the range, and add the newly added, complexity O (1:
 1 var i,j,n,k,tmp:longint; 2     f:array[0..1500,0..1500] of longint; 3 begin 4   assign(input,‘input.txt‘);assign(output,‘output.txt‘); 5   reset(input);rewrite(output); 6   readln(n,k); 7   fillchar(f,sizeof(f),0); 8   for i:=1 to n do f[i,0]:=1; 9   for i:=2 to n do10    begin11     tmp:=f[i-1,0];12     for j:=1 to k do13      begin14       if j-i>=0 then dec(tmp,f[i-1,j-i]);15       inc(tmp,f[i-1,j]);16       f[i,j]:=(tmp+10000) mod 10000;17      end;18    end;19   writeln(f[n,k]);20   close(input);close(output);21 end.  
View code

 

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.