FZU 2156 Climb Stairs

來源:互聯網
上載者:User

標籤:acm   dp   

 Problem 2156 Climb Stairs Problem Description

Jason lives on the seventh floor. He can climb several stairs at a time, and he must reach one or more specific stairs before he arrives home because of obsessive-compulsive disorder.

Let us suppose:

1. Jason can climb X stairs or Y stairs at a time.

2. Jason wants to reach the N th stairs.

3. Jason must reach the Ath stairs and the Bth stairs before he reaches the Nth stairs.

Now, Jason wants to know how many ways he can reach the Nth stairs.

 Input

The input will consist of a series of test cases.

Each test case contains five integer: N, X, Y, A, B.

0<N<=10,000

0<X, Y<=10,000

0<A, B<=N

 Output

For each test case, output the answer mod 1,000,000,007.

 Sample Input3 1 2 2 15 2 3 1 1 Sample Output10
代碼:
/***   dp, 當走到i+x層時,dp[i+x]=dp[i]+dp[i+x]*   即上升x層後到達樓層的ways = 上升之前的ways + 上升後樓層以前的ways**/#include <stdio.h>#include <string.h>#define MAX 10005int dp[MAX];int n, x, y, a, b;int fun(int l, int r){for (int i = l; i <= r; i++){if ((i + x) <= r)dp[i + x] = (dp[i] + dp[i + x]) % 1000000007;if ((i + y) <= r)dp[i + y] = (dp[i] + dp[i + y]) % 1000000007;}return dp[r] % 1000000007;}int main(){while (scanf("%d%d%d%d%d", &n, &x, &y, &a, &b) != EOF){if (a > b){ int m = a; a = b; b = m; }memset(dp, 0, sizeof(dp));dp[0] = 1;int u1 = fun(0, a);if (0 == u1){ puts("0"); continue; }int u2 = fun(a, b);if (0 == u2){ puts("0"); continue; }int ans = fun(b, n) % 1000000007;printf("%d\n", ans);}return 0;}

FZU 2156 Climb Stairs

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.