結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー kotamanegi
提出日時 2017-03-24 22:34:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,300 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 93,392 KB
実行使用メモリ 95,104 KB
最終ジャッジ日時 2024-07-06 03:07:04
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long dp[300][300][300] = {};
int main() {
	int gx, gy, n, f;
	cin >> gx >> gy >> n >> f;
	for (int i = 0;i <= 100;++i) {
		for (int q = 0;q <= 100;++q) {
			for (int j = 0;j <= 50;++j) {
				dp[i][q][j] = 100000000;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int t = 0;t < n;++t) {
		long long x, y, c;
		cin >> x >> y >> c;
		for (int i = 0;i <= gx;++i) {
			for (int q = 0;q <= gy;++q) {
				dp[i + x][q + y][t + 1] = min(dp[i + x][q + y][t + 1], dp[i][q][t] + c);
				dp[i][q][t+1] = min(dp[i][q][t + 1], dp[i][q][t]);
			}
		}
	}
	long long ans = 100000000;
	for (int i = 0;i <= gx;++i) {
		for (int q = 0;q <= gy;++q) {
			ans = min(ans, (gx - i + gy - q)*f + dp[i][q][n]);
		}
	}
	cout << ans << endl;
	return 0;
}
0