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 ...
随机推荐
- windows下更新python报错permission denied
注意退出所有python进程,可能是在使用中导致权限不足以删除
- iOSNSDate的相关操作
//获取当前时间 时间根据格林威治时间显示 //时间 8小时 英国格林威治 7小时 NSDate *date = [NSDate date]; NSLog(@"%@",date ...
- c语言-error C2440: “static_cast”: 无法从“UINT (__thiscall CHyperLink::* )(CPoint)”转换为“LRESULT (__thiscall CWnd::* )(CPoint)”
出现这个错误的原因可是“人力不可抗拒”之原因造成的,因为旧版本的 ON_WM_NCHITTEST 宏使用了 UINT (__thiscall CWzButton::* )(CPoint); 类型的类成 ...
- html 框架属性
<html> <head> <title></title> </head> <frameset col ...
- 命令 shell 学习
for i in a b c do echo $i done !ser 历史补全 > 正确信息输出文件 >>正确信息输出文件 ,追加 2>错误信息输出文件 2>> ...
- crossdomain 可用
<cross-domain-policy> <allow-access-from domain="*"/> <allow-http-request-h ...
- Ubuntu 网管服务器配置
1.设置Linux内核支持ip数据包的转发 echo "1" > /proc/sys/net/ipv4/ip_forward or vi /etc/sysctl.conf ...
- psql 命令总结
1 登录数据库 Connection options: -h, --host=HOSTNAME database server host or socket directory (default: & ...
- 改变vim配色:安装colorscheme【转】
主要有两种方式安装colorscheme: 自行下载colorscheme安装,下载的文件扩展名通常为.vim. 通过安装相关vim的插件获取. 自行下载colorscheme安装 以mac为例,在系 ...
- string 转 int,int 转 string
string str="12345"; int b=atoi(str.c_str()); 可以配合atof,转为double char buf[10]; sprintf(buf, ...