fork download
  1. class WinScore{
  2. static final int totalScore=50;
  3. static final int[] list={2,3,4,5,6,7,8};
  4. public static int methodNum=0;
  5.  
  6. static void visitTree( int achieved , int index){
  7. if (achieved >= totalScore ){
  8. return;
  9. }
  10. for ( int i=index; i< list.length; i++ ){
  11. if ( achieved + list[i] == totalScore ) {
  12. methodNum++;
  13. }else if ( achieved + list[i] < totalScore ){
  14. visitTree( achieved + list[i], i );
  15. }
  16. }
  17. }
  18. public static void main( String[] args ){
  19. visitTree(0, 0);
  20. System.out.println("number of methods are:" + methodNum );
  21.  
  22. }
  23. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
number of methods are:3095