結果

問題 No.158 奇妙なお使い
コンテスト
ユーザー ぴろず
提出日時 2015-02-27 00:28:00
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 1,133 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 225 ms
コンパイル使用メモリ 42,004 KB
最終ジャッジ日時 2026-02-23 18:07:32
ジャッジサーバーID
(参考情報)
judge5 / judge2
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <math.h>

int a1000;
int a100;
int a1;
int b1000;
int b100;
int b1;
int db;
int c1000;
int c100;
int c1;
int dc;
int dp[11][101][10001];
int max(int a,int b) {
	return a > b ? a : b;
}
int dfs(int a,int b,int c) {
	int i,j;
		if (a < 0 || b < 0 || c < 0) {
			return 0; //苦し紛れ
		}
		if (dp[a][b][c] >= 0) {
			return dp[a][b][c];
		}
		int ret = 0;
		for(i=0;i<=a;i++) {
			for(j=0;j<=b;j++) {
				int bx = db - i * 1000 - j * 100;
				if (bx >= 0 && bx <= c) {
					ret = max(ret, dfs(a-i+b1000, b-j+b100, c-bx+b1) + 1);
				}
				int cx = dc - i * 1000 - j * 100;
				if (cx >= 0 && cx <= c) {
					ret = max(ret, dfs(a-i+c1000, b-j+c100, c-cx+c1) + 1);
				}
			}
		}
		return dp[a][b][c] = ret;
	}
int main() {
	scanf("%d",&a1000);
	scanf("%d",&a100);
	scanf("%d",&a1);
	scanf("%d",&db);
	scanf("%d",&b1000);
	scanf("%d",&b100);
	scanf("%d",&b1);
	scanf("%d",&dc);
	scanf("%d",&c1000);
	scanf("%d",&c100);
	scanf("%d",&c1);
	int i,j,k;
	for(i=0;i<=10;i++) {
		for(j=0;j<=100;j++) {
			for(k=0;k<=10000;k++) {
				dp[i][j][k] = -1;
			}
		}
	}
	printf("%d\n",dfs(a1000,a100,a1));
	return 0;

}
0