zoj1163 the staircases (basic DP)

Source: Internet
Author: User

Topic links

Test instructions: give you a n, ask you to have a variety of ways to put the steps.

Requires that the following grid number is strictly greater than the number of squares above, the steps must be at least two layers and above (so the final output to 1)

There are steps to look backwards, upside down, the far right is the bottom, I ... The heart is extremely rush to collapse ...

That means we just enumerate the longest edge h on the far right, and then the rest is n-h, which is clearly calculated.

Initialize dp[0] = 1, because any n can be assumed to be a layer.

The code is as follows:

#include <cstdio> #include <cstring>typedef long long ll;int n;ll dp[505];int main () {memset (DP, 0, sizeof (DP) );DP [0] = 1;for (int j = 1; J <=; J + +) {for (int i =; i > 0; i--) {if (i >= j) dp[i] + = Dp[i-j];}} while (~SCANF ("%d", &n) && N) {printf ("%lld\n", dp[n]-1);} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

zoj1163 the staircases (basic DP)

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.