Last active
July 12, 2020 15:43
-
-
Save halitanildonmez/3e97aed3731dfe639df89276ba6464cd to your computer and use it in GitHub Desktop.
Solution for the Kickstart 2020 Round A solved as a practice version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
public class Solution { | |
public static void main(String[] args) { | |
Scanner sc = | |
new Scanner(new BufferedReader(new InputStreamReader(System.in))); | |
int T = sc.nextInt(); | |
for (int testCase = 1; testCase <= T; testCase++) { | |
int N = sc.nextInt(); | |
int K = sc.nextInt(); | |
int P = sc.nextInt(); | |
int[][] sum = new int[N+1][K+1]; | |
int[][] dp = new int[N+1][P+1]; | |
for (int i = 1; i <= N; i++) { | |
for (int j = 1; j <= K; j++) { | |
int ai = sc.nextInt(); | |
sum[i][j] = ai + sum[i][j-1]; | |
} | |
} | |
for (int i = 1; i <= N; i++) { | |
for (int j = 0; j <= P; j++) { | |
dp[i][j] = 0; | |
for (int x = 0, isum = 0; x <= Math.min(j, K); x++) { | |
dp[i][j] = Math.max(dp[i][j], sum[i][x] + dp[i-1][j-x]); | |
} | |
} | |
} | |
System.out.println("Case #" + testCase + ": " + dp[N][P]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment