解题思路:
注意事项:
参考代码:
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 人评分
【魔板】 (C++代码)(时间超限,希望会的帮我改正一下)浏览:741 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:514 |
1126题解浏览:594 |
判定字符位置 (C语言代码)浏览:799 |
1052题解(链表操作)浏览:674 |
青年歌手大奖赛_评委会打分 (C语言代码)浏览:2149 |
【偶数求和】 (C++代码)浏览:700 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:1200 |
P1002 (C语言代码)浏览:961 |
整数分类 oj上总是wrong answer浏览:664 |