20140708

今天的testB调错告诉我一件事,做了算法调整之后,千万注意数组空间是否在一些无关紧要的歩奏越界,不然天知道会出些什么鬼魅的错误。

在DP的时候,只要压维,单调性的理解就显得尤为重要,具体的表现是循环时变量的改变方向一类的细节。

testA复习了一下数位DP,但据说正解是数学推导。naive。

testC周长除以二

今天比较水,难得

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
long long dp[52][2002],c[2008][52];
long long t,k,n,v,s;
int main()
{
	freopen("testB.in","r",stdin);
	freopen("testB.out","w",stdout);
	cin>>t;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for (int z=1;z<1003;z++)
	{
		for (int i=50;i>=0;i--)
		{
			for (int j=z;j<=1003;j++)
			{
				dp[i+1][j]+=dp[i][j-z];
				dp[i+1][j]%=1000000007;
			}
		}
	}
	memset(c,0,sizeof(c));
	for (int i=1;i<1003;i++)
	{
		c[i][0]=1;
		c[i][i]=1;
	}
	for (int i=2;i<1003;i++)
	{
		for (int j=1;j<min(i,50);j++)
		{
			c[i][j]=c[i-1][j]+c[i-1][j-1];
			c[i][j]%=1000000007;
		}
	}
	for (int i=0;i<t;i++)
	{
		cin>>n>>k;
		if (k>50)
		{
			cout<<0<<endl;
			continue;
		}
		s=0;
		for (int j=k;j<=n;j++)
		{
			v=(dp[k][j]%1000000007)*(c[n-j+k][k]%1000000007)%1000000007;
			s=(v+s)%1000000007;
		}
		for (int z=2;z<=k;z++)
		{
			s=s*z%1000000007;
		}
		cout<<s<<endl;
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/201312lyx/p/3832127.html