본문 바로가기

반응형

Algorithm_이코테

(4)
[이코테 DP] 04. 병사 배치하기 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; #define MAX 2001 int n; vector ar; vector dp(MAX, 1); int main() { ios::sync_with_stdio(false); // 계산시간 단축 // 문제마다 오류 유무 다름 cin.tie(NULL); cout.tie(NULL);// 입출력 시간 단축 // 전투력 역순으로 입력 cin >> n; for (int i = 0; i > num; ar.push_bac..
[이코테 DP] 03. 효율적인 화폐구성 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 #define _CRT_SECURE_NO_WARNINGS #include #include #include using namespace std; // 주어진 지폐들을 이용해서 원하는 값을 만들 때 최소지폐갯수 구하기 #define MAX 30001 int n, m; vector ar; vector dp(MAX,10001); // 10001로 초기화해서 원소없음을 표현 int main() { ios::sync_with_stdio(false); // 계산시간 단축 // 문제마다 오류 유무 다름 cin.tie(..
[이코테 DP] 02. 1로 만들기 123456789101112131415161718192021222324252627282930#define _CRT_SECURE_NO_WARNINGS#include #include #include using namespace std;// 문제 n까지 연산의 최솟값 구하기// -1,/2,/3,/5 연산 가능 #define MAX 30001int n,minN;vector dp(MAX);int main(){ ios::sync_with_stdio(false); // 계산시간 단축 // 문제마다 오류 유무 다름 cin.tie(NULL); cout.tie(NULL);// 입출력 시간 단축 cin >> n; // dp -1,/2,/3,/5 4가지 연산중 최소값을 고려 // dp점화식: ai=min(ai-1, ai/2,..
[이코테 DP] 01. 개미전사 1234567891011121314151617181920212223242526272829#define _CRT_SECURE_NO_WARNINGS#include #include #include using namespace std; #define MAX 1001int n;vector ar;vector dp(MAX);int main(){ ios::sync_with_stdio(false); // 계산시간 단축 // 문제마다 오류 유무 다름 cin.tie(NULL); cout.tie(NULL);// 입출력 시간 단축 cin >> n; for (int i = 0; i > num; ar.push_back(num); } dp[0] = ar[0]; dp[1] = max(ar[0], ar[1]); for (int i = ..

반응형