Tuesday, May 16, 2017

【UVa】Brick Wall Patterns

Problem here

Solution

*記得要開long long int
#include <iostream>
#include <memory.h>
using namespace std;
long long int dp[51];
int main(){
    int n;
    memset(dp, 0, sizeof(dp));
    dp[0] = 0;
    dp[1] = 1;
    dp[2] = 2;
    for(int i = 3; i <= 50; i++)
        dp[i] = dp[i-1] + dp[i-2];
    while(cin >> n){
        if(n == 0)
            break;
        cout << dp[n] << endl;
    }
    return 0;
}

No comments:

Post a Comment