提出番号 | 2185 |
---|---|

提出者 | hamuhei4869 |

言語 | C++ |

提出日時 | 2018-11-02 16:44:13 |

問題名 | (70)アルゴリズムのお勉強 |

結果 | WA |

点数 | 0% |

テストケース | 結果 | 得点 | 実行時間 | メモリ使用量 |
---|---|---|---|---|

1 | WA | 0% | 2ms | 8480KB |

2 | WA | 0% | 2ms | 8464KB |

3 | WA | 0% | 2ms | 8432KB |

4 | WA | 0% | 2ms | 8464KB |

5 | WA | 0% | 2ms | 8448KB |

6 | WA | 0% | 1ms | 7536KB |

7 | WA | 0% | 1ms | 8512KB |

8 | WA | 0% | 2ms | 8320KB |

9 | WA | 0% | 2ms | 7616KB |

10 | WA | 0% | 2ms | 8208KB |

11 | WA | 0% | 2ms | 8240KB |

12 | WA | 0% | 2ms | 8416KB |

13 | WA | 0% | 2ms | 8432KB |

14 | WA | 0% | 2ms | 7552KB |

15 | WA | 0% | 2ms | 8192KB |

16 | WA | 0% | 2ms | 8224KB |

17 | WA | 0% | 2ms | 7600KB |

18 | WA | 0% | 2ms | 8432KB |

19 | WA | 0% | 3ms | 8496KB |

20 | WA | 0% | 3ms | 8240KB |

21 | WA | 0% | 2ms | 8320KB |

22 | WA | 0% | 3ms | 8416KB |

23 | WA | 0% | 2ms | 8240KB |

24 | WA | 0% | 6ms | 8320KB |

25 | WA | 0% | 2ms | 8480KB |

26 | WA | 0% | 4ms | 8416KB |

27 | WA | 0% | 5ms | 7568KB |

28 | WA | 0% | 3ms | 8416KB |

29 | WA | 0% | 21ms | 15632KB |

30 | WA | 0% | 4ms | 8192KB |

```
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define COUTDOUBLE(v) cout << std::setprecision(10)<<(v)<<endl;
#define CIN(n) int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) <<endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()
#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
int from,to,value;
Edge(LL a,LL b,LL c){
from = a;
to = b;
value = c;
}
Edge(LL a,LL b){
from = a;
to = b;
}
};
int N;
int dist[21][21];
int dp[(1 << 20)+1][21];
int rec(int bit,int v){
if(dp[bit][v] != -1)return dp[bit][v];
if(bit == (1<<v)){
return dp[bit][v]=0;
}
int res = INF;
int prev_bit = bit & ~(1<<v);
for(int u = 0;u < N;u++){
if(!(prev_bit & (1<<u)))continue;
if(res > rec(prev_bit, u) + dist[u][v]){
res = rec(prev_bit, u) + dist[u][v];
}
}
return dp[bit][v]=res;
}
int main(){
cin >> N;
I vec;
REP(a,N){
CIN(b);
vec.push_back(b);
}
REP(a,N){
REP(b,N){
CIN(c);
dist[a][b] = max(vec.at(b) - c,0);
}
}
for(int bit = 0;bit < (1<<N);bit++){
for(int v = 0; v < N;v++){
dp[bit][v]=-1;
}
}
int res = INF;
for(int v = 0;v < N;v++){
if(res > rec((1<<N)-1,v) + vec.at(v)){
res = rec((1<<N)-1, v) + vec.at(v);
}
}
COUT(res);
rt 0;
}
```