2016沈阳网络赛 QSC and Master
QSC and Master
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Enter
from the north gate of Northeastern University,You are facing the main
building of Northeastern University.Ninety-nine percent of the students
have not been there,It is said that there is a monster in it.
QSCI am a curious NEU_ACMer,This is the story he told us.
It’s
a certain period,QSCI am in a dark night, secretly sneaked into the
East Building,hope to see the master.After a serious search,He finally
saw the little master in a dark corner. The master said:
“You and I, we're interfacing.please solve my little puzzle!
There
are N pairs of numbers,Each pair consists of a key and a value,Now you
need to move out some of the pairs to get the score.You can move out two
continuous pairs,if and only if their keys are non coprime(their gcd
is not one).The final score you get is the sum of all pair’s value which
be moved out. May I ask how many points you can get the most?
The answer you give is directly related to your final exam results~The young man~”
QSC is very sad when he told the story,He failed his linear algebra that year because he didn't work out the puzzle.
Could you solve this puzzle?
(Data range:1<=N<=300
1<=Ai.key<=1,000,000,000
0<Ai.value<=1,000,000,000)
Each
test case start with one integer N . Next line contains N
integers,means Ai.key.Next line contains N integers,means Ai.value.
3
1 2 3
1 1 1
3
1 2 4
1 1 1
4
1 3 4 3
1 1 1 1
2
0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=5e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
ll dp[maxn][maxn],a[maxn],b[maxn],sum[maxn];
int main()
{
int i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(dp,,sizeof dp);
rep(i,,n)scanf("%lld",&a[i]);
rep(i,,n)scanf("%lld",&b[i]),sum[i]=sum[i-]+b[i];
rep(i,,n)
{
for(j=;j+i-<=n;j++)
{
if(gcd(a[j],a[j+i-])!=&&dp[j+][i-]==sum[j+i-]-sum[j])dp[j][i]=b[j]+b[j+i-]+dp[j+][i-];
for(k=j+;k<=j+i-;k++)dp[j][i]=max(dp[j][i],dp[j][k-j]+dp[k][j+i-k]);
}
}
printf("%lld\n",dp[][n]);
}
//system("Pause");
return ;
}
2016沈阳网络赛 QSC and Master的更多相关文章
- 2016 年沈阳网络赛---QSC and Master(区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...
- 2016沈阳网络赛 odd-even number
odd-even number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2018 ICPC 沈阳网络赛
2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- 沈阳网络赛 F - 上下界网络流
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
- 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...
- 沈阳网络赛D-Made In Heaven【k短路】【模板】
One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci ...
- 沈阳网络赛G-Spare Tire【容斥】
17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an} can be expressed as: \display ...
随机推荐
- .net 应用Memcached 缓存 demo(非转载,文件下载地址有效)
一.准备: Memcaced服务端下载地址: http://files.cnblogs.com/sjns/memcached_en32or64.rar Memcaced 客户端类库:http://fi ...
- HDU 5776 sum
猜了一下,发现对了.n>m是一定有解的.所以最多m*m暴力,一定能找到.而T较小,所以能过. #pragma comment(linker, "/STACK:1024000000,10 ...
- c语言-三字符组
C 源程序源字符集在 7 位 ASCII 字符集中包含,但设置为 ISO 646-1983 固定的代码的超集. 三字符序列允许 C 程序编写使用 " 仅 ISO (国际标准组织的固定的代码. ...
- Asp.net中,点击GridView表头实现数据的排序
一.实现该功能的基本工作. 1. 先添加一个GridView,取名为gvData. 2. 设置该控件的属性: 操作步骤如下 设置属性: 这4个属性,还要设置该控件AllowSorting=&quo ...
- 《JS权威指南学习总结--3.8类型转换》
JS数据类型转换方法主要有三种: 转换函数.强制类型转换.利用js变量弱类型转换. 一.转换函数 parseInt()和parseFloat()两个转换函数. ...
- java字符串格式化
转自:JAVA字符串格式化-String.format()的使用(转) 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语 ...
- 编辑器phpstrom的快捷键修改
file->setting-->查找 keymap -->查找 format 格式化代码 ctrl+alt +L appearance-->外观-->显示行号
- 2.请尝试安装和配置JDK,并给出安装、配置JDK的步骤。
win10/64位 1.解压jdk1.8.0_91_x64.rar 2.同时按住win键和pause键,弹出系统属性窗口,选择高级系统设计选项. 3.然后单击环境变量按钮. 4.弹出环境变量对话框后, ...
- html5结合flash实现视频文件在所有主流浏览器兼容播放
来源:http://blog.csdn.net/freshlover/article/details/7535785/ 由于html5的出现,让网页中的视频.音频有了更加便捷的实现方式.但是video ...
- MVC(@html.action)调用子操作方法
1*简单调用 子操作方法: 服务端 客户端 2.带有参数的调用 子操作方法 服务端 客户端