結果
問題 | No.107 モンスター |
ユーザー |
|
提出日時 | 2017-12-05 23:21:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,928 bytes |
コンパイル時間 | 969 ms |
コンパイル使用メモリ | 93,200 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 17:57:41 |
合計ジャッジ時間 | 2,021 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#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 1<<25 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; vi a,b,d; vi dp; void input(){ cin>>N; d.resize(N+1); dp.resize(1<<N,0); rep(i,N)cin>>d[i]; } /* int ans=0; int dfs(int S,int now,vi t){ if(S>=(1<<N)-1){ // rep(i,t.size())PP(t[i]) // P(now) ans=max(ans,now); return 0; } if(dp[S]!=-1)return dp[S]; int ret=-INF; int MAX_HP=100; rep(i,N){ if((S>>i)&1){ if(d[i]<0){ MAX_HP+=100; } } } rep(i,N){ if((S>>i)&1)continue; t.pb(i); int tmp=-INF; if(d[i]<0){ if(now+d[i]>0){ tmp=dfs(S|1<<i,now+d[i],t)+d[i]; } else tmp=-INF; } else{ tmp=dfs(S|1<<i,min(now+d[i],MAX_HP),t)+d[i]; } ret=max(ret,tmp); t.pop_back(); } //P(ret) return dp[S]=ret; }*/ signed main(){ cin.tie(0); ios::sync_with_stdio(false); input(); vi t; // dfs(0,100,t); dp[0]=100; rep(S,1<<N){ if(dp[S]==0)continue; int MAX_HP=100; rep(i,N){ if((S>>i)&1&&d[i]<0)MAX_HP+=100; } rep(i,N){ if((S>>i)&1)continue; int next=min(MAX_HP,dp[S]+d[i]); dp[S+(1<<i)]=max(dp[S+(1<<i)],next); } } P(dp[(1<<N)-1]) return 0; }