提交 5a52fa1e 编写于 作者: qq_36480062's avatar qq_36480062

c

上级 6e70626c
package basic.two;
import java.math.BigDecimal;
import java.util.Scanner;
public class 二分开方 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
double l = 0, r = n;
while (r - l > 1e-9) {
double mid = (l + r) / 2;
if (mid * mid >= n) r = mid;
else l = mid;
}
System.out.printf("%.3f", l);
}
static void dk(BigDecimal b) {
BigDecimal r = b.abs();
BigDecimal l = BigDecimal.ZERO;
for (int i = 0; i < 100; i++) {
BigDecimal mid = l.add(r).divide(BigDecimal.valueOf(2));
if (mid.multiply(mid).compareTo(b) > 0) r = mid;
else l = mid;
}
System.out.println(l.toPlainString());
}
}
......@@ -22,7 +22,6 @@ import java.util.Scanner;
* 1 2 5
* 2 3 -3
* 1 3 4
* <p>
* 输出样例:
* 2
* Bellman-Ford算法的时间复杂度为O(mn),处理本题显然会超时,
......
package graph;
import java.io.*;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import static java.lang.System.in;
/**
* 给定一个n个点m条边的有向图,图中可能存在重边和自环,所有边权均为正值。
......@@ -40,26 +43,28 @@ public class dijkstra {
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
public static void main(String[] args) throws IOException {
// Scanner sc = new Scanner(System.in);
n = nextInt();
m = nextInt();
int s = nextInt();
int a, b, c;
for (int i = 0; i < m; i++) {
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
a = nextInt();
b = nextInt();
c = nextInt();
add(a, b, c);
}
Arrays.fill(dis, Integer.MAX_VALUE);
dij();
Arrays.fill(dis, (1 << 31) - 1);
dij(s);
}
private static void dij() {
q.add(new node(1, 0));
dis[1] = 0;
private static void dij(int s) throws IOException {
q.add(new node(s, 0));
dis[s] = 0;
while (!q.isEmpty()) {
node p = q.poll();
//pq每次取出的边,就是算出最短路径的边
if (vis[p.to]) continue;
vis[p.to] = true;
for (int i = he[p.to]; i != 0; i = ne[i]) {
......@@ -70,9 +75,10 @@ public class dijkstra {
}
}
}
if (dis[n] != Integer.MAX_VALUE)
System.out.println(dis[n]);
else System.out.println("No");
for (int i = 1; i <= n; i++) {
bw.write(dis[i] + " ");
}
bw.flush();
}
static void add(int a, int b, int c) {
......@@ -84,12 +90,35 @@ public class dijkstra {
static int n, m, cnt = 1;
static int[] e = new int[100005];
static int[] he = new int[100005];
static int[] ne = new int[100005];
static int[] w = new int[100005];
static int[] e = new int[500005];
static int[] he = new int[500005];
static int[] ne = new int[500005];
static int[] w = new int[500005];
static boolean[] vis = new boolean[100005];
static PriorityQueue<node> q = new PriorityQueue<node>();
static int[] dis = new int[100005];
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static BufferedReader reader = new BufferedReader(new InputStreamReader(in));
static StringTokenizer tokenizer = new StringTokenizer("");
static String nextLine() throws IOException {// 读取下一行字符串
return reader.readLine();
}
static String next() throws IOException {// 读取下一个字符串
while (!tokenizer.hasMoreTokens()) {
//如果没有字符了,就是下一个,使用空格拆分,
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {// 读取下一个int型数值
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {// 读取下一个double型数值
return Double.parseDouble(next());
}
}
package graph;
import java.io.*;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import static java.lang.System.in;
/**
* 给定一个n个点m条边的无向图,图中可能存在重边和自环,边权可能为负数。
......@@ -38,16 +41,16 @@ import java.util.Scanner;
* 在则说明边的两个顶点均已加入并查集中,不可再添加边了。
*/
public class kruskal {
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
PriorityQueue<node> q = new PriorityQueue<node>();
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
//Scanner sc = new Scanner(System.in);
n = nextInt();
m = nextInt();
int a, b, c;
for (int i = 0; i < m; i++) {
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
a = nextInt();
b = nextInt();
c = nextInt();
q.add(new node(a, b, c));
}
int res = 0;
......@@ -62,7 +65,7 @@ public class kruskal {
}
if (cnt==n-1)
System.out.println(res);
else System.out.println("No");
else System.out.println("orz");
}
static boolean is(int p, int q) {
......@@ -108,4 +111,27 @@ public class kruskal {
}
return x;
}
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static BufferedReader reader = new BufferedReader(new InputStreamReader(in));
static StringTokenizer tokenizer = new StringTokenizer("");
static String nextLine() throws IOException {// 读取下一行字符串
return reader.readLine();
}
static String next() throws IOException {// 读取下一个字符串
while (!tokenizer.hasMoreTokens()) {
//如果没有字符了,就是下一个,使用空格拆分,
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {// 读取下一个int型数值
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {// 读取下一个double型数值
return Double.parseDouble(next());
}
}
package graph;
import java.util.Arrays;
import java.io.*;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import static java.lang.System.in;
/**
* 给定一个n个点m条边的无向图,图中可能存在重边和自环,边权可能为负数。
......@@ -38,17 +41,17 @@ import java.util.Scanner;
*/
public class prim {
static class node implements Comparable<node> {
int x, y, z;
int x, y, w;
public node(int x, int y, int w) {
this.x = x;
this.y = y;
this.z = w;
this.w = w;
}
@Override
public int compareTo(node node) {
return z - node.z;
return w - node.w;
}
@Override
......@@ -56,48 +59,44 @@ public class prim {
return "node{" +
"x=" + x +
", y=" + y +
", z=" + z +
", z=" + w +
'}';
}
}
public static void main(String[] args) {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
m = sc.nextInt();
n = nextInt();
m = nextInt();
int a, b, c;
for (int i = 0; i < g.length; i++) {
Arrays.fill(g[i], Integer.MAX_VALUE);
}
for (int i = 0; i < m; i++) {
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
g[a][b] = g[b][a] = Math.min(g[a][n], c);//处理自环边
a = nextInt();
b = nextInt();
c = nextInt();
add(a, b, c);
add(b, a, c);
}
int res = prim();
if (res == -1) System.out.println("NO");
if (res == -1) System.out.println("orz");
else System.out.println(res);
}
private static int prim() {
vis[1] = true;
int res = 0;
for (int i = 1; i <= n; i++) {
if (g[1][i] != Integer.MAX_VALUE) q.add(new node(1, i, g[1][i]));
for (int i = he[1]; i != 0; i = ne[i]) {
q.add(new node(1, e[i], w[i]));
}
int cnt = 0;
while (!q.isEmpty()) {
node min = q.poll();
if (vis[min.x] && vis[min.y]) continue;
res += min.z;
res += min.w;
cnt++;
int newV = vis[min.x] ? min.y : min.x;
vis[newV] = true;
for (int i = 1; i <= n; i++) {
if (g[newV][i] != Integer.MAX_VALUE && !vis[i]) {
q.add(new node(newV, i, g[newV][i]));
}
for (int i = he[newV]; i != 0; i = ne[i]) {
q.add(new node(newV, e[i], w[i]));
}
}
if (cnt != n - 1) return -1;
......@@ -106,8 +105,42 @@ public class prim {
static PriorityQueue<node> q = new PriorityQueue<node>();
static boolean[] vis = new boolean[510];
static int n, m;
static int[][] g = new int[510][510];
static boolean[] vis = new boolean[5100];
static int n, m, cnt = 1;
static int[] he = new int[5010];
static int[] ne = new int[400100];
static int[] e = new int[400100];
static int[] w = new int[400100];
static void add(int a, int b, int c) {
w[cnt] = c;
e[cnt] = b;
ne[cnt] = he[a];
he[a] = cnt++;
}
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static BufferedReader reader = new BufferedReader(new InputStreamReader(in));
static StringTokenizer tokenizer = new StringTokenizer("");
static String nextLine() throws IOException {// 读取下一行字符串
return reader.readLine();
}
static String next() throws IOException {// 读取下一个字符串
while (!tokenizer.hasMoreTokens()) {
//如果没有字符了,就是下一个,使用空格拆分,
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {// 读取下一个int型数值
return Integer.parseInt(next());
}
static double nextDouble() throws IOException {// 读取下一个double型数值
return Double.parseDouble(next());
}
}
......@@ -21,7 +21,7 @@ import java.util.Scanner;
* Yes
* 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),
* 并且图中的每条边(i,j)所关联的两个顶点i和j分别属于这两个不同的顶点集(i in A,j in B),
* 则称图G为一个二分图。简单的说,就是让图中任意一条边上的两个顶点都属于不同的集合即可,比如下图
* 则称图G为一个二分图。简单的说,就是让图中任意一条边上的两个顶点都属于不同的集合即可,如下
*/
public class 染色判断二分图 {
public static void main(String[] args) {
......
......@@ -37,18 +37,11 @@ public class 排队打水 {
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
qzh();
Arrays.sort(a, 0, n);
int s = 0;
long sum = 0;
/**
* 显然a[]是升序的
* 第1个需要等待0
* 第2个需要等待a[0]
* 第3个需要等待a[0]+a[1]
* 第4个需要等待a[0]+a[1]+a[2]
* ...
* 第i个需要∑ a[i] i=0->i-2 i从0开始到i-2
*/
for (int i = 0; i < n; i++) {
sum += s;
s += a[i];
......@@ -56,6 +49,30 @@ public class 排队打水 {
System.out.println(sum);
}
/**
* 推导前缀和实现,上面代码实现是等价的
* 显然a[]是升序的,因为先执行工作时长短的,会使总等待时长更小
* 第1个需要等待0
* 第2个需要等待a[0] 也就是第一个的工作时长
* 第3个需要等待a[0]+a[1]
* 第4个需要等待a[0]+a[1]+a[2]
* ...
* 第i个需要∑ a[i] i=0->i-2 i从0开始到i-2
*/
static void qzh() {
Arrays.sort(a, 0, n);
int s = 0;
//前缀和从1开始没有边界问题
for (int i = 1; i <= n; i++) {
b[i] += (b[i - 1] + a[i - 1]);
if (i <= n - 1)
s += b[i];
}//再变形-->
System.out.println(Arrays.toString(b));
System.out.println(s);
}
static int[] b = new int[100005];
static int[] a = new int[100005];
static int n;
}
package greedy;
/**
* https://blog.csdn.net/njuptACMcxk/article/details/104337089
*/
public class 货仓选址 {
public static void main(String[] args) {
}
}
package 区间dp;
import java.util.Arrays;
import java.util.Scanner;
public class 环形石子合并 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
a[i + n] = a[i];
}
for (int i = 0; i < N; i++) {
Arrays.fill(f[i], Integer.MAX_VALUE / 2);
Arrays.fill(g[i], Integer.MIN_VALUE / 2);
}
for (int i = 1; i <= n * 2; i++) {
s[i] += s[i - 1] + a[i];
}
for (int len = 1; len <= n; len++) {
for (int l = 1; l + len - 1 <= n * 2; l++) {
int r = l + len - 1;
if (len == 1) f[l][r] = g[l][r] = 0;
else {
for (int i = l; i < r; i++) {
f[l][r] = Math.min(f[l][r], f[l][i] + f[i + 1][r] + s[r] - s[l - 1]);
g[l][r] = Math.max(g[l][r], g[l][i] + g[i + 1][r] + s[r] - s[l - 1]);
}
}
}
}
int minv = Integer.MAX_VALUE / 2, maxv = Integer.MIN_VALUE / 2;
for (int i = 1; i <= n; i++) {
minv=Math.min(f[i][i+n-1],minv);
maxv=Math.max(g[i][i+n-1],maxv);
}
System.out.println(minv);
System.out.println(maxv);
}
static int n, N = 410;
static int[] s = new int[N];
static int[] a = new int[N];
static int[][] f = new int[N][N];
static int[][] g = new int[N][N];
}
......@@ -24,8 +24,15 @@ import java.util.Scanner;
* 22
* 状态定义:f[i,j]是合并i~j位所需的最小代价的集合
* 属性:min 最小代价
* 状态划分:f[i,j]划分,i i+1 ... k ... j-1
* 状态划分考虑last
* ___ _____
* __ ______
* _ _______
* ____ ____
* ...
* 可以由以上状态转移到f[i,j],分界点不同,
* 状态划分:f[i,j]划分,i i+1 ... k ... j-1
* 可以由上面状态转移过来,左边,右边
* 起码有两堆,不失一般性,考虑k,i~k k+1~j
* i~k合并的最小代价结合状态定义恰好是f[i,k]
* k+1,j合并的最小代价结合状态定义恰好是f[k+1,j]
......@@ -38,8 +45,8 @@ public class 石子合并 {
n = sc.nextInt();
for (int i = 1; i <= n; i++) {
s[i] = sc.nextInt();
s[i] += s[i - 1];
}//前缀和
s[i] += s[i - 1];//前缀和
}
for (int i = 0; i < dp.length; i++) {
Arrays.fill(dp[i], -1);
}
......
package 区间dp;
import java.util.Scanner;
public class 能量项链 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
a[i + n] = a[i];
}
for (int len = 3; len <= n + 1; len++) {//枚举长度
for (int l = 1; l + len - 1 <= n * 2; l++) {
int r = l + len - 1;
for (int k = l; k < r; k++) {
f[l][r] = Math.max(f[l][r], f[l][k] + f[k][r] + a[l] * a[r] * a[k]);
}
}
}
int res = 0;
for (int i = 1; i <= n; i++) {
res = Math.max(res, f[i][i + n]);
}
System.out.println(res);
}
static int[] a = new int[210];
static int[][] f = new int[210][210];
static int n;
}
package 计数dp;
package 数位dp;
/**
* 给定两个整数 a 和 b,求 a 和 b 之间的所有数字中0~9的出现次数。
......
package 数学;
//线性筛质数
//https://blog.csdn.net/qq_30277239/article/details/103687477
public class 线性筛 {
public static void main(String[] args) {
long s = System.nanoTime();
......@@ -15,7 +16,6 @@ public class 线性筛 {
static boolean[] vis = new boolean[10000];
//让每个合数只被它的最小质因子筛选一次,以达到不重复的目的。
//太过牛逼只能背下来
static void ol(int n) {
for (int i = 2; i <= n; i++) {
if (!vis[i]) prime[cnt++] = i;
......@@ -26,6 +26,7 @@ public class 线性筛 {
}
}
//求第N个质数是多少
static void oldN(int N) {
int n = 6000000;
int r = 0;
......
package 树形dp;
import java.util.Scanner;
public class 树的最长路径 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c;
n = sc.nextInt();
for (int i = 0; i < n - 1; i++) {
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
add(a, b, c);
add(b, a, c);
}
dfs(1, -1);
System.out.println(ans);
}
//树只能往下走,不能往上走
private static int dfs(int u, int fa) {
int dist = 0;//表示从当前点往下走的最大长度
int d1 = 0, d2 = 0;
for (int i = he[u]; i != 0; i = ne[i]) {
int j = e[i];
if (fa == j) continue;
int d = dfs(j, u) + w[i];
dist = Math.max(dist, d);
if (d >= d1) {
d2 = d1;
d1 = d;
} else if (d > d2) d2 = d;
}
ans = Math.max(d1 + d2, ans);
return dist;
}
static int n, N = 10010, M = N * 2, cnt = 1, ans;
static int[] he = new int[N];
static int[] ne = new int[M];
static int[] e = new int[M];
static int[] w = new int[M];
static void add(int a, int b, int c) {
e[cnt] = b;
w[cnt] = c;
ne[cnt] = he[a];
he[a] = cnt++;
}
}
package 状态压缩dp;
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.min;
/**
* * https://blog.csdn.net/qq_30277239/article/details/103992712
* 给定一张 n个点的带权无向图,点从 0~n-1 标号,求起点 0 到终点 n-1 的最短Hamilton路径。
* Hamilton路径的定义是从 0 到 n-1 不重不漏地经过每个点恰好一次。
* 输入格式
* 第一行输入整数n。
* 接下来n行每行n个整数,其中第i行第j个整数表示点i到j的距离(记为a[i,j])。
* 对于任意的x,y,z,数据保证 a[x,x]=0,a[x,y]=a[y,x] 并且 a[x,y]+a[y,z]>=a[x,z]。
* 输出格式
* 输出一个整数,表示最短Hamilton路径的长度。
* 数据范围
* 1≤n≤20
* 0≤a[i,j]≤10^7
* 输入样例:
* 5
* 0 2 4 5 1
* 2 0 6 5 3
* 4 6 0 8 3
* 5 5 8 0 5
* 1 3 3 5 0
* 输出样例:
* 18
* 状压dp
* 该图是完全图
*
*/
public class 哈密尔顿回路 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
g[i][j] = sc.nextInt();
}
}
for (int i = 0; i < f.length; i++) {
Arrays.fill(f[i], 0x3f3f3f3f);
}
f[1][0] = 0;
for (int i = 1; i < 1 << n; i++) {
if ((i & 1) == 0) continue;
for (int j = 0; j < n; j++) {
if (((i >> j) & 1) == 1) {
int t = i - (1 << j);
int s = t - 1 != 0 ? 1 : 0;
for (int k = s; k < n; k++) {
if ((t >> k & 1) == 1) {
f[i][j] = min(f[i][j], f[t][k] + g[k][j]);
}
}
}
}
}
System.out.println(f[(1 << n) - 1][n - 1]);
}
static int N = 20, M = 1 << 20, n;
static int[][] g = new int[N][N];
static int[][] f = new int[M][N];
}
......@@ -63,7 +63,7 @@ public class 种玉米 {
if (judge(j) && (j & a[i]) == 0) {
for (int k = 0; k < 1 << n; k++) {
if (judge(k) && (k & a[i - 1]) == 0 && (j & k) == 0)
f[i][j] = f[i][j] + f[i - 1][k] % (int) 1e8;
f[i][j] =( f[i][j] + f[i - 1][k] )% (int) 1e8;
}
}
......
package 状态压缩dp;
import java.util.Arrays;
import java.util.Scanner;
/**
* https://blog.csdn.net/qq_30277239/article/details/103986576
* 求把N*M的棋盘分成1*2的长方形有多少种方案
* 输入包含多组测试用例。
* 每组测试用例占一行,包含两个整数N和M。
* 当输入用例N=0,M=0时,表示输入终止,且该用例无需处理。
* 输出格式
* 每个测试用例输出一个结果,每个结果占一行。
* 数据范围
* 1≤N,M≤11
* 输入样例:
* 1 2
* 1 3
* 1 4
* 2 2
* 2 3
* 2 4
* 2 11
* 4 11
* 0 0
* 输出样例:
* 1
* 0
* 1
* 2
* 3
* 5
* 144
* 51205
* 本题要求将n*m的格子划分为若干个1*2的长方形,
* 求总的划分方案数,或者说在棋盘上放置若干个1*2的长方形使得它们刚好能够覆盖整个棋盘的方案数。
* 长方形要么横放要么竖放,我们知道了所有放置横向方格的位置,其它空的地方自然全部放上竖的方格,
* 也就是说,求放置的方案数等同于求放置横向方格的方案数。
* 状态表示:这里将二维压缩为一维,如果方格有五行,则第i列的状态可以表示为11011,
* 其中1表示从该位置开始横向放置1*2的长方形,
* 0则表示没有放置。则f[i][j]表示第i列状态为j的方案数。首先考虑状态转移的约束条件。
*/
public class 蒙德里安的梦想 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b;
while (true) {
n = sc.nextInt();
m = sc.nextInt();
if (n == m && n == 0) break;
for (int i = 0; i <= 1 << n; i++) {
int cnt = 0;
vis[i] = true;
for (int j = 0; j < n; j++) {
if ((i >> j & 1) == 1) {
if ((cnt & 1) == 1) vis[i] = false;
cnt = 0;
} else cnt++;
}
if ((cnt & 1) == 1) vis[i] = false;
}
for (int i = 0; i < f.length; i++) {
Arrays.fill(f[i], 0);
}
f[0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 1 << n; j++) {
for (int k = 0; k < 1 << n; k++) {
if ((j & k) == 0 && vis[(j | k)]) f[i][j] += f[i - 1][k];
}
}
}
System.out.println(f[m][0]);
}
}
static int N = 12, M = 1 << N, n, m;
static long[][] f = new long[N][M];
static boolean[] vis = new boolean[M];
}
......@@ -38,6 +38,11 @@ import java.util.Scanner;
* 将所有不存在相邻1的合法状态都存进向量a中,并统计出每个状态包含1的数量。
* 另外,a中的合法状态可以转移到哪些合法的状态,也可以预处理出来存进向量b中。
* 本题方案数可能很大,需要用long long存储。
* <p>
* f[i,j,k]
* 状态定义:所有只从前i行摆放,已经摆了j个国王,并且第i行的摆放状态是k的所有方案的集合
* 属性count
*
*/
public class 骑士 {
public static void main(String[] args) {
......
package 状态机模型;
/**
*
*/
public class 设计密码 {
public static void main(String[] args) {
}
}
package 组合dp;
/**
* 有n个无区别的物品,将它们划分成不超过m组,
* 求出划分方法数模M的余数
* <p>
* 1≤m≤n≤1000
* 2≤M≤10000
* <p>
* 输入示例:
* n=4
* m=3
* M=10000
* 输出:
* 4(1+1+2=1+3=2+2)
*/
public class 划分数 {
public static void main(String[] args) {
HuaFen(4, 3, 10000);
}
public static int HuaFen(int n, int m, int M) {
int[][] dp = new int[m + 1][n + 1];
dp[0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= n; j++) {
if (j - i >= 0) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % M;
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
System.out.println(dp[m][n]);
return dp[m][n];
}
}
......@@ -12,6 +12,7 @@ public class m任取n满足 {
static int ans, n = 6, m = 2;
static int[] arr = {2, 3, 5, 6, 1, 7};
//u是当前第几位,sum是当前选了几个,s是当前和
static void f(int u, int sum, int s) {
if (sum + n - u < m) return;//n-u是剩余可选的数,
if (u == 6) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册