⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dicegames.java

📁 通过JAVA编写的一个小游戏,键盘打字练习
💻 JAVA
字号:
package docAndJUnit;

import java.util.Arrays;

/**
 * Count formations without regard to order.Thus, {1, 1, 2}, {1, 2, 1}, and {2, 1, 1} are all the same
 * formation, whereas {1, 1, 2}, {1, 2, 2} and {1, 1, 3} are all different formations. 
 * 
 * @author 吴诗阳
 * @see java.util.Arrays;
 */
public class DiceGames {
	
	/**
	 * Count different formations depond on the given sides
	 * 
	 * @param sides
	 * 				Number of sides the dice have
	 * @return Count of different formations
	 */
	public long countFormations(int[] sides) {
		if(sides==null||sides.length==0||sides.length>32)return -1;
		
		for(int i=0;i<sides.length;i++)
			if(sides[i]>32||sides[i]<1)return -1;
	    Arrays.sort(sides);//排序
	    long[][] ret = new long[sides.length][sides[sides.length - 1]];
	    for (int i = 0; i < sides[0]; i++)
	    	 ret[0][i] = 1;
	    for (int i = 1; i < sides.length; i++)
	        for (int j = 0; j < sides[i]; j++)
	            for (int k = 0; k <= j; k++)
	                ret[i][j] += ret[i - 1][k];
	    long res = 0;
	    for (int i = 0; i < sides[sides.length - 1]; i++)
	        res += ret[sides.length - 1][i];
	    return res;
	}
	

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DiceGames g=new DiceGames();
		int[] sides={32,32,32,32,32,32};
		long result=g.countFormations(sides);
		System.out.println("result:"+result);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -