Game tree, dynamic programming (computational good sub-problems stored, direct access later)

Source: Internet
Author: User
public class Gametree {
/**
* Judge the number of remaining balls, who can take the last who wins,
*, one to take, the default we first take, and can win, can return true, otherwise false
* @param x number of balls
* @return
/static Boolean f (int x) {
int[] op={1,3,7,8};//can only have four cases per fetch
(int i=0;i< op.length;i++) {
if (X>=op[i]) {
if (f (x-op[i)) ==false) return true;//game theory, the other side must lose, then we will win
}
} Return
false;//No matter how they go, all is true, then we must lose
}
The public static void main (string[] args) {
//is dynamically programmed to increase efficiency, the computed child problem is stored, and the
System.out.println (f ()) is taken directly later;
    
}
    
    
}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.