当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 洛谷P2196 挖地雷(dp)

洛谷P2196 挖地雷(dp)

2018年10月26日  | 移动技术网IT编程  | 我要评论

西风烈 下载,衢州一中教师招聘,中国梦的手抄报

## 题意 [题目链接](https://www.luogu.org/problemnew/show/p2196) ## sol 早年noip的题锅好多啊。。 这题连有向边还是无向边都没说(~~害的我wa了一遍~~) 直接$f[i]$表示到第$i$个点的贡献 转移的时候枚举从哪个点转移而来 然后我就用一个$n^2$的算法过了一道$n \leqslant 20$的题??。。 ```cpp #include #include #include using namespace std; const int maxn = 101; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0'="" ||="" c=""> '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9')="" x="x" *="" 10="" +="" c="" -="" '0',="" c="getchar();" return="" x="" *="" f;="" }="" int="" n,="" a[maxn],="" ca[maxn][maxn],="" f[maxn],="" pre[maxn],="" ed;="" int="" main()="" {="" n="read();" for(int="" i="1;" i=""><= n;="" i++)="" a[i]="read();" for(int="" i="1;" i=""><= n;="" i++)="" for(int="" j="i" +="" 1;="" j=""><= n;="" j++)="" ca[i][j]="ca[j][i]" =="" read();="" int="" ans="0;" for(int="" i="1;" i=""><= n;="" i++)="" {="" for(int="" j="1;" j=""><= i="" -="" 1;="" j++)="" if(ca[i][j]="" &&="" f[j]=""> f[i]) f[i] = f[j], pre[i] = j; f[i] += a[i]; if(f[i] > ans) ans = f[i], ed = i; } vector v; while(ed) v.push_back(ed), ed = pre[ed]; for(int i = v.size() - 1; i >= 0; i--) printf("%d ", v[i]); puts(""); printf("%d", ans); return 0; } ```

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网