关注
package sdkd_2019_4th;
import java.util.Scanner;
public class t6 {
static int max=-1;
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
String str[]=new String[n];
int rs[]=new int[n];
for(int i=0;i<n;i++) {
str[i]=s.next();
rs[i]=s.nextInt();
}
for(int i=0;i<n;i++) {
max=0;
f(str[i].substring(1),rs[i],Integer.parseInt(str[i].substring(0,1)));
System.out.println(max);
}
}
public static void f(String str,int num,int count) {
if(count==num&&str.equals("")) {
System.out.println(str);
max++;
return;
}
for(int i=0;i<str.length();i++) {
int a=Integer.parseInt(str.substring(i, i+1));
for(int j=0;j<2;j++) {
if(j==0) {
count=count+a;
f(str.substring(i+1),num,count);
count=count-a;
}else {
count=count-a;
f(str.substring(i+1),num,count);
count=count+a;
}
}
}
return;
}
}
哪里不行啊,求解
查看原帖
点赞 2
牛客热帖
更多
正在热议
更多
# 在大厂上班是一种什么样的体验 #
14934次浏览 215人参与
# 工作前VS工作后,你的心态变化 #
38477次浏览 267人参与
# 论秋招对个人心气的改变 #
15912次浏览 241人参与
# 秋招想进国企该如何准备 #
125417次浏览 617人参与
# 程序员找工作至少要刷多少题? #
23935次浏览 313人参与
# 你的mentor是什么样的人? #
51563次浏览 740人参与
# 从mentor身上学到了__ #
55591次浏览 886人参与
# 我和mentor的爱恨情仇 #
106658次浏览 968人参与
# 我的省钱小妙招 #
37586次浏览 446人参与
# 机械人避雷的岗位/公司 #
44792次浏览 319人参与
# 为了减少AI幻觉,你注入过哪些设定? #
7429次浏览 213人参与
# 职场上哪些行为很加分? #
323124次浏览 3618人参与
# 通信/硬件求职避坑tips #
139948次浏览 1087人参与
# 你觉得mentor喜欢什么样的实习生 #
48735次浏览 1002人参与
# 你现在会用到哪些AI技能? #
24813次浏览 137人参与
# 牛客AI体验站 #
9215次浏览 230人参与
# 毕业论文进行时 #
27641次浏览 153人参与
# 运营来爆料 #
77414次浏览 467人参与
# 过年最难忘的一件事 #
23323次浏览 179人参与
# 应届生进小公司有什么影响吗 #
118968次浏览 1162人参与