HDU 2686 Matrix By Assassin 多线程dp
来源:互联网 发布:php redis 消息队列 编辑:程序博客网 时间:2024/05/16 10:15
Matrix
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2427 Accepted Submission(s): 1284
Problem Description
Yifenfei very like play a number game in the n*n Matrix. A positive integer number is put in each area of the Matrix.
Every time yifenfei should to do is that choose a detour which frome the top left point to the bottom right point and than back to the top left point with the maximal values of sum integers that area of Matrix yifenfei choose. But from the top to the bottom can only choose right and down, from the bottom to the top can only choose left and up. And yifenfei can not pass the same area of the Matrix except the start and end.
Input
The input contains multiple test cases.
Each case first line given the integer n (2
#include<iostream>#include<stdio.h>#include<string.h>#define input freopen("input.txt","r",stdin)using namespace std;long long dp[32][32][32];long long mp[32][32];int n;int inrange(long long x1,long long y1,long long x2){ if(x1==1&&y1==1&&x2==1) return 1; if(x1==x2) return 0; if(x1>=1&&x1<=n&&y1>=1&&y1<=n&&x2>=1&&x2<=n&&x1+y1-x2>=1&&x1+y1-x2<=n&&x1<=x2)return 1; return 0;}int main(){ //input; int i,j,k1,k2; while(scanf("%d",&n)!=EOF){ memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ scanf("%lld",&mp[i][j]); } } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ for(k1=1;k1<=n;k1++){ if(i==1&&j==1&&k1==1){ dp[1][1][1]=mp[1][1]; continue; } else if(i==n&&j==n&&k1==n){ dp[n][n][n]=dp[n-1][n][n]+mp[n][n]; continue; } else{ long long maxx=0; bool flag=false; if(inrange(i-1,j,k1-1)) flag=true,maxx=max(maxx,dp[i-1][j][k1-1]); if(inrange(i-1,j,k1)) flag=true,maxx=max(maxx,dp[i-1][j][k1]); if(inrange(i,j-1,k1-1)) flag=true,maxx=max(maxx,dp[i][j-1][k1-1]); if(inrange(i,j-1,k1)) flag=true,maxx=max(maxx,dp[i][j-1][k1]); if(inrange(i,j,k1)&&flag==true) dp[i][j][k1]=maxx+mp[i][j]+mp[k1][i+j-k1]; //cout<<i<<" "<<j<<" "<<k1<<" "<<i+j-k1<<" "<<dp[i][j][k1]<<endl; } } } } cout<<dp[n][n][n]<<endl; } return 0;}
- HDU 2686 Matrix By Assassin 多线程dp
- HDU 2686 Matrix (多线程DP)
- hdu 2686 Matrix (多线程dp)
- HDU 2686 Matrix(多线程DP)
- hdu 2686 Matrix【多线程DP】
- 【DP】 HDU 2686 Matrix 多线程DP
- 蓝桥杯 算法训练 方格取数 By Assassin [多线程dp]
- HDU 2955 Robberies by Assassin
- HDU 2571 命运 by Assassin
- HDU 2159 FATE by Assassin
- HDU 5965 扫雷 By Assassin
- Matrix - HDU 2686 dp
- hdu 2686 Matrix - 最小费用最大流 或 多线程DP
- hdu 2686 Matrix(最大费用流||多线程DP)@
- 树状dp入门 HDU 1561 The more, The Better By Assassin
- HDU 4028 The time of a day By Assassin dp+离散化!
- HDU 1506 City Game by Assassin
- HDU 1069 Monkey and Banana by Assassin
- *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DeviceStatusDetail
- Fatal NI connect error 12170错误解决办法
- ARM64的__create_page_tables代码走读
- Lamda OrderBy之后再GroupBy,排序没有作用.
- spring boot web
- HDU 2686 Matrix By Assassin 多线程dp
- Raft一致性协议实现源码
- body{font-size: 62.5%;}这种写法的原因
- SQL那些事儿(十二)--DATASET 与 DATAREADER区别
- python爬虫笔记 --------scrapy框架(1)
- Android照片墙加强版,使用ViewPager实现画廊效果
- 每日一练---js动态添加删除table行
- Red Hat Linux 6 安装 JDK8 和 Tomcat8
- leetcode (23) - Merge k Sorted Lists