jyukki published on 2017-11-23 included in 백준 https://www.acmicpc.net/problem/2293
풀이: 첫번째 동전부터 경우의 수를 더해감. 코드: 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 #include <iostream>using namespace std; int coin[10001] = { 0 }; int main(void) { int a; int num; cin >> a; cin >> num; int *q = new int[a]; for (int i = 0; i < a; i++){ cin >> q[i]; } for (int i = 0; i <= num; i++){ if (i%q[0] == 0) coin[i]++; } for (int i = 1; i < a; i++){ for (int t = q[i]; t <= num; t++){ coin[t] += coin[t - q[i]]; } } cout << coin[num] << endl; return 0; }
jyukki published on 2017-11-22 included in 백준 https://www.acmicpc.net/problem/3613
풀이: java 변수면 c++로 c++ 이면 java로 변경 예외처리 코드: 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 31 32 33 34 35 36 37 38 39 40 41 42 43 #include <iostream>#include <string.h>using namespace std; int main(void) { char a[201]; char b[201] = {'\n'}; bool java = false; bool cplus = false; bool ero = true; cin >> a; int t = 0; for (int i = 0; i < strlen(a); i++) { if (65 <= (int)a[i] && (int)a[i] <= 90) { if (i == 0 || cplus == true) { ero = false; break; } b[t] = '_'; t++; b[t] = a[i] + 32; java = true; } else if (a[i] == '_') { if (i == 0 || i == strlen(a)-1 || a[i + 1] == '_' || java == true || (65 <= (int)a[i + 1] && (int)a[i + 1] <= 90)) { ero = false; break; } b[t] = a[i + 1] - 32; i++; cplus = true; } else b[t] = a[i]; t++; } if (ero == false) cout << "Error!
jyukki published on 2017-11-21 included in sw https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14ABYKADACFAYh&
풀이: int[100][100] 배열에 사다리를 저장 사다리 끝에 있는 도착점을 찾음 사다리 위로 올라가며 옆에 길이 있나 확인 맨 위에 x값을 출력 코드: 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 31 32 33 34 35 36 #include <iostream>#include <string>using namespace std; int lineup(int n[100][100], int yc, int xc, bool left, bool right) { if (yc == 0) return xc; if (xc > 0 && right == false && n[yc][xc - 1] == 1) return lineup(n, yc, xc - 1,true,false); else if (xc < 99 && left==false && n[yc][xc + 1] == 1) return lineup(n, yc, xc + 1,false,true); else return lineup(n, yc - 1, xc,false,false); } int main(void) { for (int t = 1; t < 11; t++) { int a; cin >> a; int line[100][100]; int count; for (int i = 0; i < 100; i++) { for (int y = 0; y < 100; y++) { cin >> line[i][y]; } } for (int i = 0; i < 100; i++) { if (line[99][i] == 2) { count = i; break; } } cout << "#" << t << " " << lineup(line, 98, count, false, false) << endl; } return 0; } }
jyukki published on 2017-11-20 included in 백준 https://www.acmicpc.net/problem/1065
풀이: 한수이면 카운트를 ++ 하는 함수를 만듦
코드: 사용언어 : c++
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 #include <iostream>using namespace std; int hannum(int n, int c) { int b = (n % 1000) / 100; int d = ((n % 1000) % 100) / 10; int f = ((n % 1000) % 100) % 10; if (n > 99) { if ((b - d == d - f) && n !
jyukki published on 2017-11-20 included in 백준 https://www.acmicpc.net/problem/1475
풀이: 방번호를 string에 저장 string 첫번째 자릿수부터 숫자를 확인 숫자에 맞는 배열에 ++ 배열에서 가장 큰 숫자를 가지고 있는 값을 출력 코드: 사용언어 : c++
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 #include <iostream>#include <string>using namespace std; int main(void) { string a; int b[10] = { 0 }; cin >> a; for (int i = 0; i < a.
jyukki published on 2017-11-20 included in 백준 https://www.acmicpc.net/problem/2098
풀이: dp[a][b]를 현제 위치가 a이고, 이때까지 방문한 도시들의 목록이 b인 여행비용의 최솟값이라고 한다. 방문한 도시들을 쉽게 나타내기 위해 비트마스크를 사용하였다. 최솟값을 구하는 문제이므로 r을 최대한 큰 수로 두고 min함수를 이용한다. 도시의 비용이 0인 경우 방문할 수 없으므로 제외시킨다. 방문 횟수가 많아 시간초과가 날 수 있으므로 메모이제이션을 한다. 순회 문제이기 때문에 시작위치는 상관없으므로 실행시간을 늘리지 않도록 주의한다. 코드: 사용언어 : c++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <iostream>#include <algorithm>using namespace std; int w[17][17],d[17][100000], n; int T(int a, int b) { if ((1 << n) - 1 == b && w[a][0] !