結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2015-06-03 18:08:34 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,293 bytes |
コンパイル時間 | 915 ms |
コンパイル使用メモリ | 71,500 KB |
実行使用メモリ | 7,332 KB |
最終ジャッジ日時 | 2024-06-26 09:12:56 |
合計ジャッジ時間 | 1,778 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <iomanip> #include <algorithm> #include <math.h> #include <string> #include <list> ///////// #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; ///////// typedef long long LL; typedef long double LD; ///////// using namespace::std; ///////// int N; int W[100]; int dp[100][10001]; bool solve(int n,int wlim){ bool ans; if( n >= N){ return false; } if(wlim == W[n]){ //成功 return true; } else if(wlim < W[n]){ //失敗 dp[n][wlim] = 0; return false; } if(dp[n][wlim] != -1){ //cout << "dp"; if( dp[n][wlim] == 0){ return false; }else{ return true; } } { ans = solve(n+1,wlim -W[n]); if(ans == true){ return ans; } ans = solve(n+1,wlim ); if(ans == true){ return ans; } } dp[n][wlim] = 0; return false; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed;// //cout << setprecision(6);// cin>>N;//[2,100] int sum=0; rep(i,N){ cin>>W[i];//[1,100] sum += W[i]; } if(sum%2 != 0){ P("impossible"); return 0; } sort(W,W+N); rep(i,N){ rep(k,10001){ dp[i][k] = -1; } } bool ans = solve(0,sum/2); if(ans == true){ P("possible"); }else{ P("impossible"); } return 0; }