Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunjung0120 committed Nov 15, 2024
1 parent 32fbcd5 commit 1d6bb36
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 18 deletions.
49 changes: 49 additions & 0 deletions Ssafy_test/src/BOJ/silver1/BOJ_10844.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package BOJ.silver1;

import java.io.*;

public class BOJ_10844 {
static int n;
static int[][] dp;

public static int DP(int dept, int num) {

if(dp[dept][num] != 0) {
return dp[dept][num]%1000000000;
}

if(num == 0) {
dp[dept][num] = DP(dept-1, num+1)%1000000000;
}else if(num == 9) {
dp[dept][num] = DP(dept-1, num-1)%1000000000;
}else{
dp[dept][num] = DP(dept-1, num-1)%1000000000 + DP(dept-1, num+1)%1000000000;
}

return dp[dept][num]%1000000000;
}

public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

n = Integer.parseInt(br.readLine());
dp = new int[n][10];

//초기화
for(int i = 0; i<10; i++) {
dp[0][i] = 1;
}

int ans = 0;

for(int i = 1; i<10; i++) {
ans += DP(n-1,i);
ans%=1000000000;
}
bw.write(ans + "\n");
bw.flush();
bw.close();
br.close();
}
}
47 changes: 47 additions & 0 deletions Ssafy_test/src/BOJ/silver1/BOJ_11057.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package BOJ.silver1;

import java.io.*;
import java.util.*;

public class BOJ_11057 {
static int num;
static int[][] dp;

public static int DP(int dept, int num) {
if(dp[dept][num] != 0) {
return dp[dept][num];
}

for(int i = num; i<10; i++) {
dp[dept][num] += DP(dept-1,i)%10007;
dp[dept][num] %= 10007;
}

return dp[dept][num]%10007;
}

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

num = Integer.parseInt(br.readLine());
dp = new int[num][10]; //dept, n

int ans = 0;

//초기화
for(int i = 0; i<10; i++) {
dp[0][i] = 1;
}

for(int i = 0; i<10; i++) {
ans += DP(num-1, i);
ans%=10007;
}

bw.write(ans + "\n");
bw.flush();
bw.close();
br.close();
}
}
20 changes: 2 additions & 18 deletions Ssafy_test/src/BOJ/silver1/BOJ_2156.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,11 @@ public static void main(String[] args) throws IOException {
if(num>=2) {
dp[num-2] = ll[num-2] + ll[num-1]; //초기화
for(int i = num-3; i>=0; i--) {
//dp[i+3] 부터 max
int a = 0;
for(int j = i+3; j< num; j++) {
a = Math.max(a, dp[j]);
}

//dp[i+2] 부터 max
int b = 0;
for(int j = i+2; j< num; j++) {
b = Math.max(b, dp[j]);
}

dp[i] = ll[i] + Math.max(ll[i+1] + a, b);
dp[i] = Math.max(ll[i]+ ll[i+1] + dp[i+3], Math.max(dp[i+1],ll[i] + dp[i+2]));
}
}

for(int i = 0; i<num; i++) {
ans = Math.max(ans, dp[i]);
}

bw.write(ans + "\n");
bw.write(dp[0] + "\n");
bw.flush();
br.close();
bw.close();
Expand Down
52 changes: 52 additions & 0 deletions Ssafy_test/src/BOJ/silver1/BOJ_9465.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package BOJ.silver1;

import java.io.*;
import java.util.*;

public class BOJ_9465 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

int num = Integer.parseInt(br.readLine());

for(int z = 0; z<num; z++) {
int n = Integer.parseInt(br.readLine());
int[][] ll = new int[2][n];
int[][] dp = new int[2][n];

int ans = 0;

for(int i = 0; i<2; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for(int j = 0; j<n; j++) {
ll[i][j] = Integer.parseInt(st.nextToken());
}
}
//초기화
dp[0][n-1] = ll[0][n-1];
dp[1][n-1] = ll[1][n-1];

if(n>=2) {
dp[0][n-2] = ll[0][n-2] + ll[1][n-1];
dp[1][n-2] = ll[1][n-2] + ll[0][n-1];

for(int j = n-3; j>=0; j--) {
for(int i = 0; i<2; i++) {
int m = Math.max(dp[0][j+2], dp[1][j+2]);

if(i == 0) {
dp[i][j] = Math.max(ll[i][j] + Math.max(dp[1][j+1], m), dp[0][j+1]);
}else { //i == 1
dp[i][j] = Math.max(ll[i][j] + Math.max(dp[0][j+1], m), dp[1][j+1]);
}
}
}
}
bw.write(Math.max(dp[1][0], dp[0][0]) + "\n");
}
bw.flush();
br.close();
bw.close();
}
}

0 comments on commit 1d6bb36

Please sign in to comment.