10-5总结

T1傻逼dp,5分钟暴力5分钟正解 100

//Copyright(c)2015 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstring>
#define mod 1000000007
using namespace std;

/*void dfs(int now,int en1,int en2)
{
	if(now==n+1){ans++;return;}
	if(en1>0 && en2>0)dfs(now+1,en1-1,en2-1);//对轰
	if(en1>0)dfs(now+1,en1-1,en2);//A攻B充,A攻B守
	if(en2>0)dfs(now+1,en1,en2-1);//A充B攻,A守B攻
	dfs(now+1,en1,en2);//A守B守
	dfs(now+1,en1+1,en2);//A守B充
	dfs(now+1,en1,en2+1);//A充B守
	dfs(now+1,en1+1,en2+1);//A充B充
}*/
/*4,21,119,707,4326,27019,171316,1098859,7112980,46384807,304339623,7135543,295383687,
403488757,754285412,781546420,431155151,549004720,504786,99010055,851998051,118357219,
907404568,421463128,481013902,990971965,359426098,944694362,557124046,811920322,51158385,
760952589,695588090,202034069,455032964,802581952,801227956,55157762,53596664,878742970,
212745736,191549936,826141573,453559719,300431424,646622255,924575777,180932529,124269743,
207633710,873953698,463145158,524548029,487809252,182711146,413384698,203915585,920524542,
74941027,841070248,370791619,330366001,7228766,884333992,543900149,609615248,346565084,
159438157,475589313,305736875,359640882,918292712,504159378,121368715,737015989,873660987,
275271778,750392454,893564948,600806499,434023623,157409047,498024775,381825768,3876250,
278094575,955171129,220227977,538084517,31250933,675203858,526556766,39394345,653533177,
976483897,598012872,320782543,700125624,513316923,586176633,722717985,807531232,410480753,
39913941,472222613,734717495,125437407,521446920,917271426,325204299,745852356,676001978,
775698118,946491016,327404074,619259018,133986881,120200144,389470548,19210355,91314725,
18668116,14493390,711082538,851701016,691232934,682048823,121578792,195852948,243837045,
260377059,295774078,516475090,945515446,472148296,640360542,153204766,843638210,37695297,
82265337,568326737,38789630,113026766,991100683,371032666,569618131,369850045,914789204,
872105106,276582341,834520524,379733898,86266332,945662102,886872943,400829227,752202756,
157886357,867972497,408180440,847208975,1232445,536236388,219001787,258127353,721905147,
563909198,499736080,216994507,297989260,759048951,991617068,236647554,127894862,470352916,
719234957,127757177,110794883,713337420,976005921,575272408,76215865,895296167,685567984,
126306710,64285743,939938889,636407275,94306467,380444000,292590154,794314305,920854396,
404281217,1723694,166874970,413862989,98580581,7582364,474809704,*/
int n;
int dp[203][203][203];
int main()
{
	freopen("bbj.in","r",stdin);
	freopen("bbj.out","w",stdout);
	cin>>n;
	dp[0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int k=0;k<=n;k++)
			{
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j+1][k])%mod;
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k+1])%mod;
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j+1][k+1])%mod;
				dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k])%mod;
				if(k!=0)dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k-1])%mod;
				if(j!=0)dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k])%mod;
				if(k!=0 && j!=0)dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k-1])%mod;
			}
		}
	}
	int ret=0;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			ret=(ret+dp[n][i][j])%mod;
		}
	}
	printf("%d\n",ret);
}
T2 想了好久,,然后发现并没有什么方法

正解是物理折射定律= =怕不怕 0


//Copyright(c)2015 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ld long double
#define eps 1e-12
using namespace std;
double X,Y;
ld x,y;
int n;
ld a[100010],v[100010];
int main()
{
	freopen("xxx.in","r",stdin);
	freopen("xxx.out","w",stdout);
	scanf("%d",&n);
	scanf("%lf%lf",&X,&Y);x=(ld)X,y=(ld)Y;
	if(x<0)x=-x;
	if(y<0)y=-y;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&X);
		a[i]=(ld)X;
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%lf",&X);
		v[i]=(ld)X;
	}
	ld l=0,r=1;
	while(fabs(l-r)>eps)
	{
		ld mid=(l+r)/2,sum=0;
		ld now=mid;
		for(int i=1;i<=n-1;i++)
		{
			ld p=a[i]/now;
			ld q=pow(p,2)-pow(a[i],2);
			if(q>0)sum+=sqrt(q);
			ld r=1-now;
			ld g=(r*a[i+1])/a[i];
			now=1-g;
		}
		
		if(sum>x)l=mid;
		else r=mid;
	}
	ld now=l,sum=0;
	for(int i=1;i<=n-1;i++)
	{
		ld p=a[i]/now;
		sum+=p;
		ld r=1-now;
		ld g=(r*a[i+1])/a[i];
		now=1-g;
	}
	printf("%0.10f",double(sum));
}
T3

更加呵呵,想到n^4发现没有这一档果断不写了 30

附带标算

//Copyright(c)2015 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstring>
#define mod 1000000007
#define ll long long
using namespace std;
ll n;
ll c[1001][1001];
ll rec[1001];
ll dp[1001];
ll ans[1001];
int main()
{
	freopen("chessboard.in","r",stdin);
	freopen("chessboard.out","w",stdout);
	scanf("%I64d",&n);
    for(int i=0;i<=n;i++)
		for(int j=0;j<=i;j++)
		{
			c[i][j]= j ? (c[i-1][j-1]+c[i-1][j])%mod : 1;
		}
			
    rec[0]=1;
	dp[0]=1;
	ans[0]=1;
    for(int i=1;i<=n;i++)rec[i]=(rec[i-1]*i)%mod;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            dp[i]=(dp[i]+c[i][j]*c[i][j]%mod*rec[j]%mod)%mod;
        }
    }
    for(int i=1;i<=n;i++)
    {
        ans[i]=dp[i]*dp[i]%mod;
        for(int j=1;j<=i;j++)
        {
            ans[i]=(ans[i]+mod-c[i][j]*c[i][j]%mod*rec[j]%mod*ans[i-j]%mod)%mod;
        }
    }
    cout<<ans[n];
    return 0;
}



你可能感兴趣的:(dp,C语言)