滴滴0928笔试,第一题只过了55%
import java.util.*; public class Main { static int n; static HashSet<String> hashSet = new HashSet<>(); static HashSet<String> ans = new HashSet<>(); public static void main(String[] args) { Scanner in = new Scanner(System.in); n = in.nextInt(); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); cut(a, b, c, 1); System.out.println(ans.size()); } public static void cut(int a, int b, int c, int now) {//剩余now次 if ( a <= 0 || b <= 0 || c <= 0 || now >n || hashSet.contains(a+","+b+","+c)) { return; } hashSet.add(a+","+b+","+c); if (a + b > c && a + c > b && b + c > a) { ans.add(a+","+b+","+c+","+now); } cut(a - now, b, c, now + 1); cut(a, b - now, c, now + 1); cut(a, b, c - now, now + 1); } }
一份只过了55%的代码,有大佬帮忙分享一下解题思路吗