HDU 5900 QSC and Master Sheng Yang 网络赛
来源:互联网 发布:mac最新系统下载地址 编辑:程序博客网 时间:2024/06/07 01:06
题解: 我们可以先通过dp判断哪些可以进行合并然后再通过一维dp 得到最大值
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#define ll long longusing namespace std;const int maxn = 505;ll d[maxn] = {0};bool dp[maxn][maxn] = {0};ll a[maxn] = {0};ll b[maxn] = {0};ll sum[maxn] = {0};ll ans = 0;int main () { ios_base :: sync_with_stdio(false); int t; cin >> t; while (t--) { int n; cin >> n; memset (d,0,sizeof (d)); memset (dp,0,sizeof (dp)); memset (sum,0,sizeof (sum)); for (int i = 1;i <= n; ++ i) cin >> a[i]; for (int i = 1;i <= n; ++ i){ cin >> b[i]; sum[i] += b[i]; sum[i] += sum[i - 1]; } for (int i = 1;i < n; ++ i) { if (__gcd(a[i],a[i + 1]) != 1) { dp[i][i + 1] = 1; } } for (int l = 3;l <= n; l += 2) { for (int i = 1;i + l <= n; ++i) { int j = i + l; for (int k = i + 1;k < j; ++ k) { if (dp[i][k] && dp[k + 1][j]) { dp[i][j] = 1; } } if (__gcd(a[i],a[j]) != 1 && dp[i + 1][j - 1]) { dp[i][j] = 1; } } } for (int i = 1;i <= n; ++ i) { d[i] = d[i - 1]; for (int j = 1;j < i; ++ j) { if (dp[j][i]) { d[i] = max (d[i],d[j - 1] + sum[i] - sum[j - 1]); } } }// cout << dp[1][n] << endl; cout << d[n] << endl; } return 0;}
阅读全文
0 0
- HDU 5900 QSC and Master Sheng Yang 网络赛
- hdu 5900 QSC and Master
- HDU-5900 QSC and Master
- hdu 5900 QSC and Master
- HDU 5900 - QSC and Master
- HDU 5900 QSC and Master
- HDU 5900 QSC and Master(2016亚洲区沈阳站网络赛)
- hdu 5900QSC and Master(区间dp 沈阳网络赛)
- hdu 5900 QSC and Master -ICPC网络赛沈阳赛区-区间dp
- hdu 5900 - QSC and Master (2016沈阳网络赛)区间dp
- 【2016-沈阳赛区网络赛-I】区间DP(QSC and Master,hdu 5900)
- hdu 5900 QSC and Master(acm/icpc沈阳网络赛,区间DP)
- hdu 5900 QSC and Master 区间dp
- hdu 5900 QSC and Master 区间dp
- HDU 5900 QSC and Master(区间dp)
- hdu 5900 QSC and Master【区间dp】
- Hdu-5900 QSC and Master(区间DP)
- HDU 5900 QSC and Master(区间DP)
- Jquery特效---购物车 代码
- 根据页面来源不同返回不同页面
- Qt学习之路
- hdu 6168 Numbers(多校联赛)
- 将一个数组中的数据按相反的顺序存储(将数组中的数据逆序输出)
- HDU 5900 QSC and Master Sheng Yang 网络赛
- node 项目常见配置文件
- Canvas知识点之二
- 顺序表构造二叉树 Java
- switch case 语法
- POJ1125Stockbroker Grapevine(最短路径)
- hdu1754 ihateit
- 根据HttpServletRequest获取用户真实IP地址
- HTML 3d动画立方体的实现