思路:
用f[i][j]表示前i个位置,其中第i个位置去变量j时的情况总数。则:
有两种符号可以选,我们先来看"<" 时,f[i][j]=Sigma(f[[i-1][j'], 1<=j'<=i-1)
“=”号时和"<"不一样,因为A=B和B=A是一样的,没关系,不是一样嘛,我们规定前边小后边大就可以了,此时f[i][j]=Sigma(f[i-1][j'],j'<j)
所以总数为f[i][j] = Sigma(f[[i-1][j'], 1<=j'<=i-1) + Sigma(f[i-1][j'],j'<j);
用f[i][j]表示前i个位置,其中第i个位置去变量j时的情况总数。则:
有两种符号可以选,我们先来看"<" 时,f[i][j]=Sigma(f[[i-1][j'], 1<=j'<=i-1)
“=”号时和"<"不一样,因为A=B和B=A是一样的,没关系,不是一样嘛,我们规定前边小后边大就可以了,此时f[i][j]=Sigma(f[i-1][j'],j'<j)
所以总数为f[i][j] = Sigma(f[[i-1][j'], 1<=j'<=i-1) + Sigma(f[i-1][j'],j'<j);
/*
2011-9-13
author:BearFly1990
*/
package acm.hdu.tests;
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;
public class HDU_1223 {
public static void main(String[] args) {
int i, j, k, t, n;
BigInteger [][]f = new BigInteger[51][51];
BigInteger tmp;
BigInteger []ans = new BigInteger[51];
Scanner cin = new Scanner(new BufferedInputStream(System.in));
f[1][1] = BigInteger.ONE;
for(i = 2; i <= 50; i++)
for(j = 1; j <= i; j++)
{
tmp = BigInteger.ZERO;
for(k = 1; k <= i-1; k++)
tmp = tmp.add(f[i-1][k]);
for(k = 1; k < j; k++)
tmp = tmp.add(f[i-1][k]);
f[i][j] = tmp;
}
for(i = 1; i <= 50; i++)
{
tmp = BigInteger.ZERO;
for(j = 1; j <= i; j++) tmp = tmp.add(f[i][j]);
ans[i] = tmp;
}
t = cin.nextInt();
while(t != 0)
{
t--;
n = cin.nextInt();
System.out.println(ans[n]);
}
}
}