| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- back propagation
- 다익스트라
- object detection
- 가끔은 말로
- 미래는_현재와_과거로
- 조합론
- 우선 순위 큐
- 2023
- 알고리즘
- Overfitting
- pytorch
- BFS
- dfs
- DP
- tensorflow
- 플로이드 와샬
- 자바스크립트
- dropout
- 문자열
- NEXT
- 너비 우선 탐색
- lazy propagation
- 크루스칼
- 회고록
- 이분 탐색
- 세그먼트 트리
- 백트래킹
- c++
- 분할 정복
- 가끔은_말로
Archives
- Today
- Total
Doby's Lab
백준 12037번: Polynesiaglot (Small1) (C++) 본문
https://www.acmicpc.net/problem/12037
12037번: Polynesiaglot (Small1)
In Case #1, suppose that the only vowel is a and the only consonant is h. Then the possible valid words of length 4 are: aaaa, aaha, ahaa, haaa, haha. In Case #2 (which would not appear in the Small dataset 1), suppose that the two vowels are a a
www.acmicpc.net
Solved By: DP
cache[i][0]: 모음으로 끝나는 길이가 i인 문자열의 개수
cache[i][0]: 자음으로 끝나는 길이가 i인 문자열의 개수
다음과 같이 세팅하고 DP를 돌렸습니다.
#include <iostream>
#define MAX 16
using namespace std;
int cache[MAX][2];
const int mod = 1000000007;
int main(){
int T; cin >> T;
int cnt = 1;
while(T--){
int c, v, l; cin >> c >> v >> l;
cache[1][0] = v;
cache[1][1] = c;
for(int i = 2; i <= l; i++){
cache[i][0] = ((v % mod) * ((cache[i - 1][0] % mod + cache[i - 1][1] % mod) % mod)) % mod;
cache[i][1] = ((c % mod) * (cache[i - 1][0] % mod)) % mod;
}
cout << "Case #" << cnt << ": ";
cout << cache[l][0] << '\n';
cnt++;
}
}
'PS > BOJ' 카테고리의 다른 글
| 백준 23832번: 서로소 그래프 (C++) (1) | 2022.08.07 |
|---|---|
| 백준 1068번: 트리 (C++) (1) | 2022.08.07 |
| 백준 11525번: Farey Sequence Length (C++) (0) | 2022.08.06 |
| 백준 2533번: 사회망 서비스(SNS) (C++) (0) | 2022.08.06 |
| 백준 15312번: 이름 궁합 (C++) (1) | 2022.08.04 |