首页 > 学院 > 开发设计 > 正文

李白打酒

2019-11-06 06:51:21
字体:
来源:转载
供稿:网友

1006.李白打酒

Description

话说大诗人李白,一生好饮。幸好他从不开车。一天,他提着酒壶,从家里出来,酒壶中有酒2斗。他边走边唱:无事街上走,提壶去打酒。逢店加一倍,遇花喝一斗。这一路上,他一共遇到店5次,遇到花10次,已知最后一次遇到的是花,他正好把酒喝光了。请你计算李白遇到店和花的次序,可以把遇店记为a,遇花记为b。则:babaabbabbabbbb 就是合理的次序。像这样的答案一共有多少呢?请你计算出所有可能方案的个数(包含题目给出的)。注意:答案是个整数。不要书写任何多余的内容。

Input

Output

正确的结果

Sample Input

 

Sample Output

10

Hint

样例输出只是输出格式参考穷举即可,也可以写14个for循环来穷举,那就台low了.可以用二进制来替换穷举。
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++;		}	}}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表