Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴搜TLE,结果打了个离散表,竟然就好了!!!实质上只要打10,10,10,d的表就可以了,我打了两个表是想测试一下速度的改善状况,所以下边的数据献给需要的人!!!

Posted by CSUST_14 at 2013-04-22 19:39:05 on Problem 1187
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int Mod = 11380;
const int N = 11;
const int M = 31;

int Dp[N][N][N][M];
int l1,l2,l3;
int d;
int arr[400][5]={6,3,2,11,1,7,9,7,12,107,1,9,4,9,3726,4,4,10,10,134,8,8,0,7,10782,
10,0,8,14,2819,0,5,5,9,27,7,1,10,6,8278,5,7,1,10,4485,5,7,4,5,8039,
6,7,0,2,7650,3,1,4,5,2212,6,0,7,13,1,3,4,8,9,9680,9,6,1,1,420,
3,5,6,3,3790,1,3,7,10,29,9,10,4,1,1410,6,5,7,6,5966,6,9,4,10,1507,
6,6,2,9,4898,6,6,8,6,6211,0,6,9,2,2506,4,10,6,19,73,7,10,9,6,7056,
4,6,1,4,3601,7,8,10,19,6678,2,3,7,5,2204,7,2,9,7,5599,6,9,9,3,4036,
2,6,7,9,4893,3,5,2,1,2520,2,7,1,8,527,0,5,9,13,35,6,2,6,6,10763,
5,10,8,13,2443,5,0,9,6,771,6,9,3,1,10040,3,9,10,18,3300,4,2,7,1,2980,
3,6,5,14,1,9,3,1,8,751,1,7,2,3,618,8,9,5,18,11051,1,7,6,4,6540,
1,2,8,4,10201,2,4,4,9,33,7,7,7,8,9070,7,6,6,15,6647,1,7,1,6,2099,
5,8,5,1,11176,8,5,0,9,10674,10,9,1,16,5385,8,6,9,3,1477,2,9,7,7,9524,
0,5,2,1,21,2,6,1,3,7069,5,0,1,6,1,0,1,9,5,8148,10,7,4,6,1332,
6,9,7,3,10036,5,0,1,5,18,8,8,2,13,1739,7,0,7,11,8983,0,0,9,1,1,
4,6,5,6,6384,2,8,10,17,1545,10,2,6,6,5641,5,1,4,8,671,3,9,8,0,0,
4,0,5,2,373,9,6,2,5,4561,5,5,2,8,10886,3,3,5,4,2649,9,1,2,8,4287,
4,9,5,6,1410,10,7,5,14,8475,8,0,9,17,1,1,7,0,6,101,4,2,1,3,4481,
1,1,0,2,1,10,2,10,8,3417,0,1,1,1,2,4,2,4,4,4537,8,6,10,19,6852,
0,6,1,6,22,1,0,4,2,43,1,10,5,6,5719,8,3,7,18,1,1,2,6,5,7387,
9,7,1,2,5192,1,4,6,0,0,8,4,9,0,0,3,10,5,9,11122,6,10,10,13,9892,
1,6,6,12,39,4,7,9,0,0,10,8,0,6,6725,9,2,6,3,10004,10,9,5,6,2584,
2,2,2,4,193,3,9,10,18,3300,0,6,1,2,329,6,7,2,2,2348,3,4,0,5,132,
8,4,8,18,2921,6,7,10,3,4461,7,4,7,17,69,2,0,1,3,1,3,6,2,3,3416,
3,2,2,4,2096,0,7,9,15,43,9,10,6,20,11160,4,5,6,7,8852,10,2,6,14,4609,
10,2,0,1,66,6,7,3,4,7589,7,5,1,0,0,3,9,5,1,7140,2,9,2,5,6802,
7,10,2,17,3360,2,0,7,4,7794,1,1,8,5,9680,2,9,2,9,11312,6,0,0,2,31,
2,6,5,5,718,5,6,4,10,7934,3,6,6,6,584,8,7,0,3,4292,6,1,0,4,477,
3,3,9,5,4002,3,10,3,3,6854,10,3,10,3,2259,4,8,1,3,8223,10,10,1,1,10676,
0,7,8,14,41,1,5,6,3,9694,5,6,6,6,8421,1,0,9,6,3233,1,9,6,3,2915,
2,0,0,0,0,9,8,4,18,7188,5,6,10,1,4572,1,1,9,2,4150,0,1,1,2,1,
5,2,2,5,8466,2,6,2,9,37,2,0,2,0,0,3,5,0,8,1,4,2,5,3,6854,
9,9,0,10,2547,0,6,5,3,3132,1,9,2,0,0,1,3,0,4,1,6,1,1,8,1,
7,4,3,5,626,5,7,9,6,8863,10,7,5,6,9904,3,3,6,0,0,7,4,10,15,2038,
2,1,9,12,1,5,4,7,12,119,4,5,7,13,3200,5,10,10,25,1,10,5,3,7,4858,
9,3,6,0,0,0,9,7,4,9336,10,2,7,3,10924,0,8,5,5,9951,3,7,2,0,0,
1,6,0,4,236,3,6,4,5,4553,3,9,10,11,7614,4,3,9,2,6700,5,4,5,5,1119,
2,1,9,4,6638,1,9,2,9,9648,3,2,3,0,0,4,10,1,15,1,5,9,5,11,3850,
6,10,8,15,5065,4,8,3,13,1705,5,8,1,6,7681,10,2,0,11,41,6,1,4,10,45,
7,9,10,20,7768,9,0,3,1,220,2,3,6,5,11066,6,7,1,13,62,7,2,0,1,36,
10,9,6,9,9523,9,4,2,5,1377,1,1,1,1,6,5,5,6,3,8741,9,5,4,15,10368,
1,2,3,3,509,5,0,10,3,785,5,6,10,1,4572,0,9,10,8,5899,7,5,9,9,1832,
7,3,4,8,4547,3,5,2,0,0,6,10,5,12,8795,9,9,10,18,7049,10,3,7,15,2032,
10,2,0,8,4526,1,2,0,1,3,9,10,0,14,10959,2,2,6,9,29,8,5,3,14,2479,
3,10,5,18,1,6,1,2,2,5364,5,3,10,6,2134,8,7,1,14,2231,10,0,0,2,511,
4,4,10,17,57,1,7,6,0,0,0,7,8,14,41,0,9,4,13,1,2,0,0,1,1,
1,0,5,5,11,6,10,4,3,1457,1,7,7,13,985,3,0,6,4,2906,9,9,3,19,4272,
8,2,0,3,2682,6,8,2,8,2106,7,2,4,10,2376,10,10,5,18,10930,5,2,4,7,3342,
9,6,0,12,2630,10,9,3,21,99,1,4,1,6,1,7,10,10,5,2828,1,10,6,1,10956,
1,1,2,3,11,2,8,8,7,7540,6,3,2,0,0,3,7,8,13,7909,5,0,0,4,7,
9,3,8,13,7901,2,9,7,10,5775,9,10,5,0,0,9,3,10,0,0,5,5,6,4,9422,
5,0,5,8,347,0,5,9,14,1,2,4,10,11,1516,2,8,2,9,57,1,6,1,5,1333,
7,9,7,8,6645,4,10,8,11,4047,6,9,5,18,3076,6,9,0,10,4574,7,5,0,5,9473,
7,4,9,19,73,5,4,4,6,4126,4,4,6,7,10902,3,0,1,1,4,7,1,0,7,26,
5,3,8,0,0,10,2,6,0,0,2,7,1,10,1,1,8,0,4,3774,6,0,2,7,25,
4,10,7,21,1,5,10,3,15,4263,9,8,10,14,11314,4,1,10,13,941,5,4,10,11,5275,
6,4,9,6,2211,9,7,10,9,9286,1,2,6,3,5168,4,2,8,1,10905,9,9,3,14,4288,
8,7,8,2,7628,7,9,1,3,1950,6,6,6,8,10460,6,5,8,19,1,7,5,1,6,4874,
0,4,1,5,1,1,3,3,1,140,8,9,4,13,2052,3,3,4,9,35,1,1,9,7,10182,
7,6,5,16,2623,3,8,9,0,0,3,1,10,11,8059,7,7,8,16,9884,4,1,6,0,0,
7,9,4,20,1,8,4,3,1,9005,5,3,2,8,878,8,3,9,16,10981,9,8,5,4,5210,
9,4,7,8,8974,6,4,4,9,9243,4,2,1,2,2938,8,7,1,1,540,4,1,2,4,1892,
9,7,8,0,0,4,4,6,12,1171,0,0,3,3,1,4,2,8,9,3310,3,1,6,9,31,
4,4,0,1,70,1,0,10,7,5190,1,5,6,12,1,6,3,3,8,5848,2,2,0,2,24,
2,8,1,6,8472,7,0,3,8,460,9,9,10,15,9073,0,9,8,4,4254,9,4,5,18,1,
3,7,1,6,7726,1,2,3,0,0,1,3,10,0,0,9,3,1,12,64,0,3,9,9,2817,
4,1,4,4,10797,9,0,5,5,8811,9,9,4,11,9704,4,5,10,6,30,3,0,9,5,5156,
1,6,6,0,0,6,4,1,6,6061,8,3,4,4,399,3,5,3,5,1307,10,8,5,1,262,
6,9,10,7,1700,5,5,10,17,2050,0,5,10,10,6739,7,1,6,7,743,3,1,5,2,2882,
6,0,3,6,2654,9,0,5,4,5820,5,1,9,0,0,3,2,8,10,8834,2,2,4,7,25,
4,0,9,4,9851,3,10,2,2,10425,0,10,8,17,53,3,5,5,4,211,2,1,4,5,191,
9,0,10,17,1374,0,10,3,0,0,1,2,6,2,7057,10,0,6,13,6848,8,6,0,5,481,
2,6,2,3,11167,2,6,5,13,1,2,6,7,3,6546,7,10,7,2,3533,3,6,10,7,3378,
3,5,0,3,5690,1,5,0,2,106,10,7,3,20,1,3,3,4,9,35,1,8,10,15,3727,
10,5,7,19,7230,10,3,3,9,3374,8,10,0,0,0,7,2,1,0,0,10,7,3,2,8784,
2,5,3,0,0,1,3,6,5,7991,1,5,5,11,1,0,1,0,1,1,4,5,7,10,3303,
2,0,10,3,8608,8,2,10,16,9845,4,0,3,0,0,9,4,5,16,2921,7,6,1,11,2699,
5,3,6,8,10823,1,4,1,1,30,7,7,2,2,9171,9,4,10,17,2038,2,2,10,5,9945,
6,7,0,11,591,7,5,0,1,792,0,3,3,4,100,5,1,7,11,920,1,3,3,2,2918,
10,9,5,0,0,0,8,4,8,4128,8,0,3,3,7197,3,10,5,5,2659,4,4,2,6,7477,
8,9,4,3,5583,9,1,5,3,4890,0,5,1,3,205,4,9,9,1,7540,0,6,6,9,5324,
3,8,5,0,0,0,2,3,0,0,0,3,3,4,100,4,2,7,6,8145,5,0,2,5,192
};

int ar[] = {9060,
1588,
878,
8362,
3753,
5671,
8557,
7841,
10062,
6450,
3587,
157,
10857,
4695,
10885,
727,
1765,
2007,
848,
1200,
6608,
5314,
1513,
2501,
11213,
5545,
9185,
6781,
117,
1
};
void init()
{
	memset(Dp,0,sizeof(Dp));
	Dp[0][0][0][0] = 1;
	for(int i=1;i<=30;i++)
		Dp[10][10][10][i] = ar[i-1];
	for(int i=0;i<400;i++)
		Dp[arr[i][0]][arr[i][1]][arr[i][2]][arr[i][3]] = arr[i][4];
}

struct P
{
	int x,y,z;
};
P predeal(int a,int b,int c)
{
	P p;
	p.x = a;p.y =b; p.z = c;
	if(p.x>0) p.x--;
	else if(p.y>0) p.y--;
	else if(p.z>0) p.z--;
	return p;
}
int dfs(int a,int b,int c,int d)
{    
	if(a+b+c<d) return 0;
	 if(a+b+c==1 && d==1)
	 {
		 Dp[a][b][c][d] = 1;
		 return 1;
	 }
	 if(Dp[a][b][c][d] > 0 ) return Dp[a][b][c][d];
	 if(d==0) return 0;
	 if(a+b+c==d){Dp[a][b][c][d] = 1;return 1;}

	 for(int i=0;i<=a;i++)
		 for(int j=0;j<=b;j++)
			 for(int k=0;k<=c;k++)
				 for(int de=1;de<=d&&de<=i+j+k;de++)
				 {
					 P te = predeal(i,j,k);
					 if(de<d)
					 {
						 if(a+b+c-i-j-k>=d)
						 Dp[a][b][c][d] += dfs(te.x,te.y,te.z,de-1) *dfs(a-i,b-j,c-k,d);
					 }
					 else
						 for(int s=1;s<=d && s<=a+b+c-i-j-k;s++)
							 Dp[a][b][c][d] += dfs(te.x,te.y,te.z,de-1)*dfs(a-i,b-j,c-k,s);
					 Dp[a][b][c][d] %= Mod;
				 }
				 P temp = predeal(a,b,c);
				 Dp[a][b][c][d] += dfs(temp.x,temp.y,temp.z,d-1);
				 Dp[a][b][c][d] %= Mod;
				 return Dp[a][b][c][d];


}
int main()
{  
	init();
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
		
		printf("%d\n",dfs(a,b,c,d));
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator