Hi.
I tried to solve the second problem of INOI 2012, Table Sum with the native approach (or the bruteforce way) as I’m not able to think of any other way in which we could attempt the problem.
After looking at a few outputs, I thought there might be some kind of pattern in the output but couldn’t find any.
Any aid would be very helpful as I’m preparing for INOI 2015 and have almost no experience in algorithmic programming. I started practicing almost a week after ZIO results were out :[
Here is my code (its in java, sorry about that):
import java.io.*;
import java.util.Scanner;
public class TABLESUM {
public static Scanner in = new Scanner(System.in);
public static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int n = in.nextInt();
int[] ar = new int[n];
int[] def = new int[n];
for (int i = 0; i < n; i++) {
ar[i] = in.nextInt();
}
for (int i = 0; i < n ; i++) {
def[i] = i+1;
}
for (int i = 0; i < n; i++) {
tableSum(ar, def);
nextPerm(def);
}
}
public static int[] nextPerm (int[] a) {
int first = a[0];
for (int i = 0; i < a.length; i++) {
if (i == a.length-1) {
a[i] = first;
}else {
a[i] = a[i+1];
}
}
return a;
}
public static void tableSum (int[] a, int[] b) {
int max = 0;
for (int i = 0; i < a.length; i++) {
if (a[i] + b[i] > max) {
max = a[i] + b[i];
}
}
pw.print(max + " ");
pw.flush();
}
}