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

嘿嘿,自己做的,记忆?递归?搞不清楚是不是dp,小弟水人一个,继续努力!

Posted by lijinwu at 2009-12-17 18:19:26 on Problem 1579
#include <iostream>
using namespace std;
int a,b,c;
int w[21][21][21];

int calw(int a,int b,int c)
{
	if(a<=0||b<=0||c<=0)
		return 1;
	if(a>20||b>20||c>20)
		return calw(20,20,20);
	if(w[a][b][c]>0)
		return w[a][b][c];
	if(a<b&&b<c)
	{
                //在这里记住它们~
		w[a][b][c-1]=calw(a,b,c-1);
		w[a][b-1][c-1]=calw(a,b-1,c-1);
		w[a][b-1][c]=calw(a,b-1,c);
		return w[a][b][c-1]+w[a][b-1][c-1]-w[a][b-1][c];
	}
	else
	{
                //在这里记住它们~
		w[a-1][b][c]=calw(a-1,b,c);
		w[a-1][b-1][c]=calw(a-1,b-1,c);
		w[a-1][b][c-1]=calw(a-1,b,c-1);
		w[a-1][b-1][c-1]=calw(a-1,b-1,c-1);
		return w[a-1][b][c]+w[a-1][b-1][c]+w[a-1][b][c-1]-w[a-1][b-1][c-1];
	}
	return w[a][b][c];
}
int main()
{	
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	int res;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF&&(a!=-1||b!=-1||c!=-1))
	{
		memset(w,0,sizeof(w));
		res=calw(a,b,c);
		printf("w(%d, %d, %d) = %d\n",a,b,c,res);
	}
	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