1006.李白打酒
Description
话说大诗人李白,一生好饮。幸好他从不开车。
一天,他提着酒壶,从家里出来,酒壶中有酒2斗。他边走边唱:
无事街上走,提壶去打酒。
逢店加一倍,遇花喝一斗。
这一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光了。
请你计算李白遇到店和花的次序,可以把遇店记为a,遇花记为b。则:babaabbabbabbbb 就是合理的次序。像这样的答案一共有多少呢?请你计算出所有可能方案的个数(包含题目给出的)。
注意:答案是个整数。不要书写任何多余的内容。
无
Output
正确的结果
Sample Output
Hint
样例输出只是输出格式参考
穷举即可,也可以写14个for循环来穷举,但是那也太差劲了.可以用二进制来替换穷举。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| public class T6 {
static int[] data=new int[15]; public static void main(String[] args) { int m=16384;//Math.pow(2, 14); int count=0; for (int i = 0; i <= m; i++) { int sum=2; int a=0; String b=""; getEr(i); for (int j = 0; j < data.length; j++) { if(data[j]==1){ sum=sum*2; a++; b=b+"a"; } else{ sum=sum-1; b=b+"b"; } } if(sum==0&&a==5){ //System.out.println(a+" "+b); count++; } } System.out.println(count); } private static void getEr(int i) { data=new int[15]; int k=0; while(i>0){ data[k]=i%2; i=i/2; k++; } } }
|