BOJ
15312 이름 궁합
공부정리
2018. 2. 17. 12:19
이항계수가 생각나는 문제다.
쌩으로 배열 만들어도 메모리가 부족하지 않을 것 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <string.h> using namespace std; int d[2][4004], c[] = { 3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1 }, len, r; char a[2002], b[2002]; int main() { scanf("%s %s", &a, &b); len = strlen(a); for (int i = 0; i < len; i++) { d[0][i*2] = c[a[i] - 'A']; d[0][i*2 + 1] = c[b[i] - 'A']; } len *= 2; r = len - 2; for (int i = 0; i < r; i++) for (int j = 0; j < len - i - 1; j++) d[(i + 1) % 2][j] = (d[i % 2][j] + d[i % 2][j + 1])%10; printf("%d%d", d[r % 2][0]%10, d[r % 2][1]%10); return 0; } | cs |