URAL 1225 Flags(DP 동적 계획)
#include <stdio.h>
#define MAX_STRIPES 45
#define COLORS 3
#define RED 0
#define WHITE 1
#define BLUE 3
int numOfStripes;
/*
* 0 (numOfStripes- 1)
* tail ( ) color ,waysOfTailColor[tail][color] 0 tail
* , waysOfTailColor[tail][RED] waysOfTailColor[tail][WHITE]
*/
long long waysOfTailColor[MAX_STRIPES][COLORS - 1];// 2^45 -3^45 , long long
int main(){
scanf("%d", &numOfStripes);
waysOfTailColor[0][RED] = waysOfTailColor[0][WHITE] = 1;
waysOfTailColor[1][RED] = waysOfTailColor[1][WHITE] = 1;
int tail;
for (tail = 1; tail < numOfStripes; tail++){
/*
* , ,
* waysOfTailColor[tail][RED] = waysOfTailColor[tail - 1][WHITE] + waysOfTailColor[tail - 1][BULE];
* ,
* waysOfTailColor[tail - 1][BULE] = waysOfTailColor[tail - 2][WHITE]
* waysOfTailColor[tail][RED] = waysOfTailColor[tail - 1][WHITE] + waysOfTailColor[tail - 2][WHITE]
* waysOfTailColor[tail][WHITE] waysOfTailColor[tail][RED]
*/
waysOfTailColor[tail][RED] = waysOfTailColor[tail - 1][WHITE] + waysOfTailColor[tail - 2][WHITE];
waysOfTailColor[tail][WHITE] = waysOfTailColor[tail - 1][RED] + waysOfTailColor[tail - 2][RED];
}
int waysOfColor = waysOfTailColor[numOfStripes - 1][RED] + waysOfTailColor[numOfStripes - 1][WHITE];
// long long
printf("%I64d
", waysOfColor);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
01 가방, 완전 가방, 다중 가방 dp(동적 기획 입문 dp)01 가방은 2진법으로 직접 표시할 수 있지만 데이터 양이 너무 많으면 시간을 초과하는 것이 폭력이다.01 가방의 사상은 바로 이 물품에 대해 내가 넣은 가치가 큰지 안 넣은 가치가 큰지 비교하여 방정식 f[i][v...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.