티스토리 뷰
문제 : https://www.acmicpc.net/problem/2011
Github : https://github.com/ddulhddul/algorithm/blob/master/src/Baekjoon2011.java
1. DP 이용해 풀었지만... 어디서 예외가 발생하는지 모르겠음
2 시간초과는 발생하지 않음.
3 0케이스 처리했는데도 예외발생
소스코드
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Baekjoon2011 {
//public class Main {
public static void main(String[] args)
throws FileNotFoundException
{
File file =new File("D:\\dev\\worksspace\\Solution\\src\\Baekjoon2011.txt");
Scanner sc = new Scanner(file);
// Scanner sc = new Scanner(System.in);
String numStr = sc.next();
//i번째자리에서 뒤로 나올 경우의수
int[] d = new int[numStr.length()+1];
for (int i = numStr.length(); i >= 0; i--) {
if(i == numStr.length()){
d[i] = 1;
}else{
d[i] = d[i+1];
if(i <= numStr.length()-2){
if(Integer.parseInt(numStr.substring(i+1, i+2)) == 0){
d[i] = d[i+2];
}else if(Integer.parseInt(numStr.substring(i, i+2)) <= 26){
d[i] = d[i+1] + d[i+2];
}
}
if(i <= numStr.length()-3){
if(Integer.parseInt(numStr.substring(i+2, i+3)) == 0){
d[i] = d[i+1];
}
}
}
}
System.out.println(numStr);
for (int i = 0; i < d.length; i++) {
System.out.println(i + " : " + d[i]);
}
System.out.println(d[0]%1000000);
}
}
'Programming > Algorithm' 카테고리의 다른 글
| [DP] 백준 알고리즘 1126번 같은 탑 (1322) | 2016.10.27 |
|---|---|
| [DP] 백준 알고리즘 1514번 자물쇠 (252) | 2016.10.26 |
| [DP] 백준 알고리즘 4781번 사탕가게 (1073) | 2016.10.25 |
| [DP] 백준 알고리즘 1017번 소수 쌍 (972) | 2016.09.19 |
| [DP] 백준 알고리즘 2758번 로또 (964) | 2016.09.18 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 중국어공부
- s9+
- 노브랜드
- 혁오
- GraphQL
- 존맛탱
- AWS nodejs
- 10cm
- 알고리즘
- 수미네 반찬
- 로꼬
- 자금조달계획서
- 뒤꿈치 건조함
- 웰빙헬스
- 크러쉬
- AWS npm
- 부동신 계약시 주의사항
- 서머너즈워
- 부동산거래계약신고필증
- Axis2
- 마시내 탕수육
- 고운발크림
- Git
- ES6
- 중국어정리
- 프리티어
- 프렌즈
- Bitnami
- 생활코딩
- 중국어강의
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
글 보관함