<span style="font-size:18px;">#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int M = 125;
int main(void)
{
//打表法求
/*1 = 1;
2 = 2;
2 = 1 + 1;
3 = 3;
3 = 2 + 1;
3 = 1 + 1 + 1;
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
5 = 5;
5 = 4 + 1;
5 = 3 + 2;
5 = 3 + 1 + 1;
5 = 2 + 2 + 1;
5 = 2 + 1 + 1 + 1;
5 = 1 + 1 + 1 + 1 + 1
a[i][j]表示i拆分放在小于等于j位置上的方法数
将i拆分并放在j个位置上,每位置至少是1,所以减去1*j,把剩下的i-j放置在j个位置上,其实就是高中排列组合题
a[5][1] = a[5][0] + a[4][1]; 0+1;
a[5][2] = a[5][1] + a[3][2]; 1+2;
a[5][3] = a[5][2] + a[2][3]; 3+2;
a[5][4] = a[5][3] + a[1][4]; 5+1;
a[5][5] = a[5][4] + a[0][5]; 6+1;
*/
int a[M][M]={{1},{1,1}}; //一维代表数值N,二位代表拆分的个数(包括小于部分)
for(int i=2;i<125;i++)
{
for(int j=1;j<=i;j++)
{
if(j>i-j) //处理二维大于一维的情况
a[i][j]=a[i][j-1]+a[i-j][i-j];
else
a[i][j]=a[i][j-1]+a[i-j][j];
}
}
int n;
while(~scanf("%d",&n))
{
printf("%d\n",a[n][n]);
// for(int i=0;i<=n;i++)
// {
// for(int j=0;j<=i;j++)
// printf("%d\n",a[i][j]);
// }
}
return 0;
} //---邱新磊</span>
Ignatius and the Princess III
最新推荐文章于 2021-08-23 16:56:27 发布