Ural 1017. Staircases

Source: Internet
Author: User

Click to open link
1017. Staircasestime limit:1.0 Second
Memory limit:64 MB
One curious child have a set of NLittle Bricks (5≤ N≤500). From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not a allowed for staircase to has steps equal sizes. Every staircase consists of at least both steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:your task is to write a program that reads the number Nand writes the only number Q-amount of different staircases that can is built from exactly NBricks. Inputnumber NOutputnumber QSample
input Output
212
995645335
problem Source:Ural State University Internal Contest ' #2
To build stairs with n bricks, the number of bricks required for the number of stairs is increasing, so how many options are there? Dp[i][j] means that the current staircase is shared with I bricks, and the last block of a total of J brick scheme number, then:
Dp[0][0]=1
dp[i][j]=sum{dp[i-j][k],0<=k<j}


0.0622 kb#include<stdio.h> #define LL Long longll Dp[507][507];int main () {    dp[0][0]=1;    for (int i=1;i<=500;i++) for (int.        j=1;j<=i;j++) for            (int k=0;k<j;k++)                dp[i][j]+=dp[i-j][k];    int n;    while (scanf ("%d", &n)!=eof)    {        ll ans=0;        for (int i=1;i<n;i++)            ans+=dp[n][i];        printf ("%lld\n", ans);    }    return 0;}


Ural 1017. Staircases

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.