-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32fbcd5
commit 1d6bb36
Showing
4 changed files
with
150 additions
and
18 deletions.
There are no files selected for viewing
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
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(); | ||
} | ||
} |
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
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(); | ||
} | ||
} |
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
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
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(); | ||
} | ||
} |