【递归】【3月周赛1】【Problem B】
来源:互联网 发布:linux系统启动执行命令 编辑:程序博客网 时间:2024/05/19 14:20
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
Given three arraies A[],B[],C[], each contains N non-negative integers.You are asked to maxmize the vale:V=max(A[i]+B[j]+C[k]), where 0<i,j,k<=N and i!=j and j!=k and i!=k.
Input
Each case contains 4 lines,
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[].
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
Each case contains a number seperately: the answer V.
Sample Input
31 2 33 2 13 2 1
Sample Output
8
思路:
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));
}
{
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();}}
0 0
- 【递归】【3月周赛1】【Problem B】
- ACM递归地推练习 Problem B
- B - The 3n + 1 problem
- 1:A+B Problem
- 1:A+B Problem
- 1 A+B Problem
- 1 A+B Problem
- A + B Problem(1)
- 1 A+B Problem
- 1 A+B Problem
- #1 A + B Problem
- 1 A+B Problem
- Problem B: Minesweeper(1)
- NYOJ 1 A+B Problem
- (1)A+B Problem
- No.1 A+B Problem
- uva 100 The 3n + 1 problem (递归)
- HDU 1032 The 3n + 1 problem【递归】
- LINUX 虚拟网卡tun例子
- 利用C语言获取网页源代码
- 数据格式化{0:#,##0}
- css学习记录1
- Java定时器周期执行任务的例子
- 【递归】【3月周赛1】【Problem B】
- 计算机底层知识拾遗(三)理解磁盘的机制
- sleep和wait的区别
- 计算机底层知识拾遗(二)深入理解进程和线程
- AD右边libraries原理图库不见时打开方式
- nyoj 5 Binary String Matching
- 数据库基本SQL语句大全
- 虚拟网卡 TUN/TAP 驱动程序设计原理与编程
- android 实现截图和图片裁剪