sgu 269 分类: sgu 2015-06-27 13:49 20人阅读 评论(0) 收藏
类似
首先对
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
const int maxl = 300, maxn = 255, maxk = maxn, Base = 10000;
struct BigNum
{
int num[maxl], l;
void digit(int t)
{
num[t+1] += num[t]/Base, num[t] %= Base;
}
BigNum operator *(const int b)
{
BigNum ret = (*this);
if(!l || !b){ret.l = 0; return ret;}
for(int i = 1; i <= l; i++) ret.num[i] *= b;
for(int i = 1; i <= l; i++) ret.digit(i);
while(ret.num[ret.l+1]) ++ret.l, ret.digit(ret.l);
return ret;
}
void operator +=(const BigNum add)
{
l = std::max(l, add.l);
for(int i = 1; i <= l; i++) num[i] += add.num[i];
for(int i = 1; i <= l; i++) digit(i);
if(num[l+1]) l++;
}
void prt()
{
printf("%d",num[l]);
for(int i = l-1; i >= 1; i--)
printf("%04d", num[i]);
}
}emp, dp[maxk];
int n, k, b[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("sgu269.in","r",stdin);
freopen("sgu269.out","w",stdout);
#endif
std::cin >> n >> k;
for(int i = 1; i <= n; i++)
std::cin >> b[i];
std::sort(b + 1, b + n + 1);
dp[0].num[1] = dp[0].l = 1;
for(int i = 1; i <= n; i++)
{
for(int j = k; j >= 1; j--)
dp[j] += dp[j-1]*(b[i]-j+1);
}
dp[k].prt();
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。