結果

問題 No.617 Nafmo、買い出しに行く
ユーザー zuvizudarzuvizudar
提出日時 2017-12-18 15:28:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 90,924 KB
実行使用メモリ 11,412 KB
最終ジャッジ日時 2023-08-22 05:27:01
合計ジャッジ時間 4,382 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 14 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 29 ms
4,380 KB
testcase_06 AC 367 ms
11,236 KB
testcase_07 AC 346 ms
11,236 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 354 ms
11,220 KB
testcase_11 AC 351 ms
11,240 KB
testcase_12 AC 351 ms
11,356 KB
testcase_13 AC 267 ms
11,352 KB
testcase_14 AC 344 ms
11,232 KB
testcase_15 AC 5 ms
11,280 KB
testcase_16 AC 5 ms
11,412 KB
testcase_17 AC 5 ms
11,340 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M,K;
vi a,b;
vi dp;
void input(){
	cin>>N>>K;
	rep(i,N){
		int tmp;
		cin>>tmp;
		a.pb(tmp);
	}
	dp.resize(1<<(N),-1);
}
int dfs(int S){
	if(S>=(1<<N)-1){
		return 0;
	}
	if(dp[S]!=-1)return dp[S];
	vi used(N,0);
	int now_g=0;
	for(int i=N-1;i>=0;i--){
		if((S>>i)&1){
			used[i]=1;
			now_g+=a[i];
		}
	}
	int res=0;
	rep(i,N){
		if(used[i])continue;
		if(now_g+a[i]<=K)
			res=max(res,dfs(S|1<<i)+a[i]);
	}
	return dp[S]=res;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	P(dfs(0));
	return 0;
}

0