Eularproject 76:Counting summations

来源:互联网 发布:4518无法网络打印 编辑:程序博客网 时间:2024/06/07 02:37

Andrew Zhang
Jul 16, 2017

It is possible to write five as a sum in exactly six different ways:

4 + 1
3 + 2
3 + 1 + 1
2 + 2 + 1
2 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1

How many different ways can one hundred be written as a sum of at least two positive integers?

Answer:
190569291
Completed on Sun, 16 Jul 2017, 00:58
Go to the thread for problem 76 in the forum.

题目解析:
简单dp。

#include <iostream>using namespace std;#define SIZE 105int main(){    int state[SIZE][SIZE];    for (int i = 0; i <= 100; i++) {        for (int j = 0; j <= i; j++) {            if ((i <= 1) || (j <= 1)) {                state[i][j] = 1;                continue;            }else{                state[i][j] = state[i - j][j] + state[i][j - 1];                continue;            }        }        for (int j = i + 1; j <= 100; j++) {            state[i][j] = state[i][i];        }    }    cout << state[100][100] << endl;    return 0;}
原创粉丝点击