結果

問題 No.27 板の準備
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-09-06 00:26:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,704 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 63,492 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:32:02
合計ジャッジ時間 1,499 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,376 KB
testcase_01 AC 13 ms
4,376 KB
testcase_02 AC 14 ms
4,376 KB
testcase_03 AC 14 ms
4,376 KB
testcase_04 AC 13 ms
4,380 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 13 ms
4,376 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 13 ms
4,380 KB
testcase_09 AC 14 ms
4,376 KB
testcase_10 AC 13 ms
4,376 KB
testcase_11 AC 13 ms
4,380 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e6;
int dp[35];//dp[i] := 長さiの板を作るのに、必要な最小の枚数
int main(void){
	int v[4];
	rep(i, 4) cin >> v[i];

	int ita[3], ans = INF;
	for (int a = 1; a <= 30; ++a){//a,b,cを全探索
		for (int b = a + 1; b <= 30; ++b){
			for (int c = b + 1; c <= 30; ++c){

				ita[0] = a; ita[1] = b; ita[2] = c;
				rep(i, 35)dp[i] = INF;//-1は作れない
				dp[a] = 1; dp[b] = 1; dp[c] = 1;//初期化

				// printf("%d %d %d\n", a, b, c);
				for (int x = 1; x <= 30; ++x){
					for (int y = 0; y < 3; ++y){//使う板
						/*
						if(1 <= x - ita[y] && x - ita[y] <= 30){
							if(dp[x - ita[y]] == -1)continue;//-1の時、その板は使えない
							dp[x] = min(dp[x - ita[y]] + 1, dp[x]);//y番目の板を使う
						}*/

						for (int z = 1; z <= 30; ++z){//同じ長さの板を何度も使うことはある
							if(1 <= x - ita[y] * z && x - ita[y] * z <= 30){
								if(dp[x - ita[y] * z] == INF) continue;//-1の時、その板は使えない
								// printf("%d \n", x - ita[y] * z);
								dp[x] = min(dp[x - ita[y] * z] + z, dp[x]);//y番目の板をz個使う
							}
						}
					}
				}

				int now = 0;
				rep(i, 4){
					if(dp[v[i]] != -1){
						now += dp[v[i]];
					}else{
						break;
					}
					if(i == 3){
						ans = min(now, ans);//v[0]~v[3]まで作れた
						// printf("%d\n", ans);
						// printf("%d %d %d\n", ita[0], ita[1], ita[2]);
						// printf("%d %d %d\n", dp[v[0]], dp[v[1]], dp[v[2]]);
					}
				}

			}
		}
	}
	cout << ans << endl;
	return 0;
}
0