【递归】【3月周赛1】【Problem B】
Problem B
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 59 Accepted Submission(s) : 27
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Input
the first line contains an integer N( 3<=N<=10000 ) ,
the second line contains N integers representing array A[],
the third line contains N integers representing array B[],
the fourth line contains N integers representing array C[].
Output
Sample Input
3
1 2 3
3 2 1
3 2 1
Sample Output
8
{
if(A[i].pos!=B[j].pos&&A[i].pos!=C[k].pos&&B[j].pos!=C[k].pos)
return A[i].l+B[j].l+C[k].l;
if(A[i].pos==B[j].pos)
return max(dfs(i+1,j,k),dfs(i,j+1,k));
if(A[i].pos==C[k].pos)
return max(dfs(i+1,j,k),dfs(i,j,k+1));
if(C[k].pos==B[j].pos)
return max(dfs(i,j+1,k),dfs(i,j,k+1));
}
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#define oo 0x13131313
using namespace std;
struct node
{
int l;int pos;
};
node A[10001],B[10001],C[10001];
int N;
int cmp(const void *i,const void *j)
{
node *ii=(node *)i,*jj=(node *)j;
return jj->l-ii->l;
}
void input()
{
for(int i=1;i<=N;i++)
{
scanf("%d",&A[i].l);
A[i].pos=i;
}
for(int i=1;i<=N;i++)
{
scanf("%d",&B[i].l);
B[i].pos=i;
}
for(int i=1;i<=N;i++)
{
scanf("%d",&C[i].l);
C[i].pos=i;
}
qsort(A+1,N,sizeof(A[1]),cmp);
qsort(B+1,N,sizeof(A[1]),cmp);
qsort(C+1,N,sizeof(A[1]),cmp);
}
int dfs(int i,int j,int k)
{
if(A[i].pos!=B[j].pos&&A[i].pos!=C[k].pos&&B[j].pos!=C[k].pos)
return A[i].l+B[j].l+C[k].l;
if(A[i].pos==B[j].pos)
return max(dfs(i+1,j,k),dfs(i,j+1,k));
if(A[i].pos==C[k].pos)
return max(dfs(i+1,j,k),dfs(i,j,k+1));
if(C[k].pos==B[j].pos)
return max(dfs(i,j+1,k),dfs(i,j,k+1));
}
void solve()
{
int ans=dfs(1,1,1);
printf("%d\n",ans);
}
int main()
{
while(cin>>N)
{
input();
solve();
}
}
【递归】【3月周赛1】【Problem B】的更多相关文章
- codevs http://www.codevs.cn/problem/?problemset_id=1 循环、递归、stl复习题
12.10高一练习题 1.要求: 这周回顾复习的内容是循环.递归.stl. 不要因为题目简单就放弃不做,现在就是练习基础. 2.练习题: (1)循环 题目解析与代码见随笔分类 NOI题库 htt ...
- 【算法】N Queens Problem
/* ** 目前最快的N皇后递归解决方法 ** N Queens Problem ** 试探-回溯算法,递归实现 */ #include "stdafx.h" #include & ...
- n皇后2种解题思路与代码-Java与C++实现
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:本文主要讲了n皇后问题的解题思路,并分别用java和c++实现了过程,最后,对于算法改进 ...
- Hanoi Tower问题分析
前言 回家休息第3天了,状态一直不是太好,主要是要补牙,检查身体,见同学见亲戚,心里又着急校招,难得能腾出时间来好好思考,这里也是看<cracking the coding interview& ...
- 深入N皇后问题的两个最高效算法的详解 分类: C/C++ 2014-11-08 17:22 117人阅读 评论(0) 收藏
N皇后问题是一个经典的问题,在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行.同一列.同一斜线上的皇后都会自动攻击). 一. 求解N皇后问题是算法中回溯法应用的一个经典案例 回溯算 ...
- 【BZOJ1791】【IOI2008】【基环树】island(status第一速度)
1791: [Ioi2008]Island 岛屿 Time Limit: 20 Sec Memory Limit: 162 MB Submit: 908 Solved: 159 [Su ...
- HDU 1754 I Hate It (段树 & 树阵)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Java 学习笔记 (二) Selenium WebDriver Java 弹出框
下面这段实例实现了以下功能: 1. profile使用用户本地电脑上的 (selenium 3有问题.因为selenium 3把profile复制到一个temp文件夹里,但并不复制回去.所以每次打开仍 ...
- 二叉树/DFS总结
二叉搜索树(Binary Search Tree,又名排序二叉树,二叉查找树,通常简写为BST)定义如下: 空树或是具有下列性质的二叉树: ()若左子树不空,则左子树上所有节点值均小于或等于它的根节点 ...
随机推荐
- ECSHOP返回顶部的代码 纯CSS超简单
在themes/模板文件夹/library/page_footer.lbi 文件的最末尾加上下面的一段代码 <style>.to_top{width:20px;height:59px;ri ...
- ThinkPHP使用Memcached缓存数据
ThinkPHP默认使用文件缓存数据,支持Memcache等其他缓存方式,有两个PHP扩展:Memcache和Memcached,Memcahe官方有说明,主要说一下Memcached. 相对于PHP ...
- sql相关操作
1.两个不同数据库对应字段相应操作 //操作模版:insert into data2.table2(字段1,字段2,字段) select 字段j,字段k,字段m from data1.table1举例 ...
- SQL日期格式转换(经常用又经常忘记的东西)转载自http://www.cnblogs.com/wangyuelang0526/archive/2012/06/06/2538224.html
Select CONVERT(varchar(100), GETDATE(), 8):14:53:14Select CONVERT(varchar(100), GETDATE(), 9): 06 6 ...
- <转>golang 并发性能数据
1.管道chan吞吐极限10,000,000,单次Put,Get耗时大约100ns/op,无论是采用单Go程,还是多Go程并发(并发数:100, 10000, 100000),耗时均没有变化,Go内核 ...
- 创建一个基本的 Win32 窗口
#include <Windows.h> //Forward declarations bool InitMainWindow(HINSTANCE, int); LRESULT CALLB ...
- Servlet Examples
Servlet Examples Servlet Examples 1.Hello World output: code: 1.import java.io.*;2.import javax.serv ...
- Angular中Controller之间的信息传递(第二种办法):$emit,$broadcast,$on
$emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...
- MFC可执行文件问题
MFC生成的.exe可执行文件,在其它机子上无法正常执行.主要是MFC库链接方式的问题,使用MFC分动态连接和静态连接两种: 静态连接就是把需要的MFC库函数放进你的exe之中,这样,在MFC库函 ...
- mysqlbinlog 读取多个文件
[root@zjzc01 binlog]# mysqlbinlog --start-datetime='2016-02-25 00:00:00' --stop-datetime='2016-03-15 ...