Ural 1260 a nudnik photographer (DP)

Source: Internet
Author: User

A nudnik photographer

 

Note:

Sort the numbers from 1 to n. 1 must be at the leftmost. The difference between two adjacent numbers cannot exceed 2. How many sort methods are available.

 

Ideas:

DP for the seat, when the first is 1, the second is 2, the combination of DP [I-1]; when the first is 1, the second is 3, the third is also determined to be 2, combined as DP [I-3]; and the last case is 1357 ...... 8642.

So the DP equation is DP [I] = DP [I-1] + dp [I-3] + 1.

 

1 # include <stdio. h> 2 3 int N; 4 int DP [2, 100]; 5 6 int main () 7 {8 scanf ("% d", & N ); 9 DP [1] = 1; 10 DP [2] = 1; 11 DP [3] = 2; 12 DP [4] = 4; 13 for (INT I = 5; I <= 55; + I) {14 DP [I] = DP [I-1] + dp [I-3] + 1; 15} 16 printf ("% d ", DP [N]); 17 18 return 0; 19}
URL 1260

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.