acDream


私信TA

用户名:acDream

访问量:32431

签 名:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

等  级
排  名 137
经  验 7330
参赛次数 4
文章发表 72
年  龄 0
在职情况 学生
学  校 黑龙江工商学院
专  业 软件工程

  自我简介:

欢迎光临CSDN博客https://blog.csdn.net/acDream_

解题思路:

注意事项:

参考代码:

public class 排队买票 {
	public static int count = 0;
	public static void qpl(char[] chars,int from,int to) {
		if(from==to) {
			int money = 0;
			int k;
			for(k=0;k<chars.length;k++) {
				if(1==Integer.valueOf(String.valueOf(chars[k]))) {
					money++;
				}
				if(2==Integer.valueOf(String.valueOf(chars[k]))){
					money--;
					if(money<0) {
						break;
					}
				}
			}
			if(k==chars.length) {
				count++;
			}
			
			return;
		}
		for(int i=from;i<=to;i++) {
			swap(chars, from, i);
			qpl(chars, from+1, to);
			swap(chars, i, from);
		}	
	}
	public static void swap(char[] chars,int i,int j) {
		char temp;
		temp = chars[i];
		chars[i] = chars[j];
		chars[j] = temp;
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int M = in.nextInt();
		int N = in.nextInt();
		int K = in.nextInt();
		StringBuffer str = new StringBuffer("");
		for(int i=0;i<N;i++) {
			str.append(1);
		}
		for(int i=0;i<K;i++) {
			str.append(2);
		}
		String s = new String(str);
		qpl(s.toCharArray(), 0, s.length()-1);
		System.out.println(count);
	}

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区