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

不知道为什么,这个算法可以过。(付Java代码),求大神解释一下原因。谢谢

Posted by 20101289 at 2013-04-06 21:27:44 on Problem 1579
 import java.util.*;
 
 public class Poj1579 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b,c;
		while(true) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			if(a==-1 && b ==-1 && c == -1)
				break;
			System.out.println("w("+a+", "+b+", "+c+") = " + w(a,b,c));
		}
		sc.close();
	}
	
	//w
	public static long w(int a,int b,int c) {
		if(a <= 0|| b <= 0 || c <= 0)
			return 1;
		if(a > 20 || b > 20 || c > 20) 
			return w(20,20,20);
		if(a <=b|| a<=c) {
			//System.out.println(w(a,b,c-1) +" "+ w(a,b-1,c-1) + " " + -w(a,b-1,c));
			//return w(a,b,c-1) + w(a,b-1,c-1) -w(a,b-1,c);
				return (long)Math.pow(2,a);
			}
		//System.out.println(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-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
	}
 }

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