题目大意是指求出符合条件的排列有多少种。
#include <iostream>
#include <cmath>
using namespace std;
int n, m;
long long dp[15][2005];//i个元素,以j结尾的排列数
void search()
{
int i, j, k;
for ( i = 1; i <= 10; ++ i)
{
for ( j = 1; j <= 2000; ++ j)
{
dp[i][j] = 0;
if ( i == 1 ) dp[i][j] = 1;
else for ( k = 0; k <= j / 2; ++ k) dp[i][j] += dp[i-1][k];
}
}
return;
}
int main()
{
int t, c = 0;
search();
cin >> t;
while ( t -- )
{
++ c;
int i;
cin >> n >> m;
long long ans = 0;
for ( i = 0; i <= m; i ++ ) ans += dp[n][i];
cout << "Case "<< c <<": n = "<< n <<", m = "<< m <<", # lists = "<< ans <<"\n";
}
return 0;
}
07-26
1830
07-10
1875