当前位置:网站首页>Digital triangle model acwing 1027. Grid retrieval
Digital triangle model acwing 1027. Grid retrieval
2022-07-27 11:19:00 【T_ Y_ F666】
Digital triangle model AcWing 1027. Take the number of squares
Original link
AcWing 1027. Take the number of squares
Algorithm tags
DP linear DP
Ideas
Wrong thinking : Go twice
Since there may be multiple solutions with the first time of travel , You can only choose one of them . But the first place you walk will be reset to 0, It is impossible to determine whether the value of the second time will be greater than the answer you have obtained when the first time is also the optimal solution and is not selected by you 





Code
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 105;
int f[2*N][N][N], a[N][N];
int aa, b, c, d;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
while(aa=read(), b=read(), c=read(), aa||b||c){
a[aa][b]=c;
}
// Sum of row and column values The row determines the column
rep(k, 2, n+n+1){
// First time i That's ok
rep(i1, 1, n+1){
// Second time i That's ok
rep(i2, 1, n+1){
// j1 It means the first time j Column j2 It means the second time j Column
int j1=k-i1, j2=k-i2;
if(j1>=1&&j1<=n&&j2>=1&&j2<=n){
int t=a[i1][j1];
// Not the same path
if(i1-i2){
t+=a[i2][j2];
}
// Next Lower right The lower right Right, right
f[k][i1][i2]=max({f[k][i1][i2], f[k-1][i1-1][i2-1]+t, f[k-1][i1-1][i2]+t, f[k-1][i1][i2-1]+t, f[k-1][i1][i2]+t});
}
}
}
}
printf("%lld", f[2*n][n][n]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
- Luogu p3052 [usaco12mar]cows in a skyscraper G
- 15 design movie rental system
- 15th largest value of data flow
- 349两个数组的交集和01两数之和
- 博弈论 AcWing 893. 集合-Nim游戏
- Description and feelings
- The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
- ACM warm-up Exercise 2 in 2022 summer vacation (summary)
- 什么是私域流量?
猜你喜欢

Tree DP acwing 285. dance without boss

Longest ascending subsequence model acwing 1010. Interceptor missile

Interval problem acwing 906. Interval grouping

Wechat push - template message parameter configuration

背包问题 AcWing 9. 分组背包问题

Influence of black and white pixel distribution on iteration times

Kangaroo cloud stack based on CBO in spark SQL optimization

tensorflow运行报错解决方法

Play with the cluster configuration center and learn about the Taier console

The difference of iteration number and information entropy
随机推荐
Longest ascending subsequence model acwing 1014. mountaineering
Thank you for your likes and attention
How to assemble a registry
Taishan Office Technology Lecture: scaling and opening files
Opengauss kernel analysis - statistics and row count estimation
State compression DP acwing 91. shortest Hamilton path
Learning notes uni app
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
2022 Niuke multi school (3) j.journey
ACM warm-up Exercise 1 in 2022 summer vacation (summary)
12 is at least twice the maximum number of other numbers
Yiwen counts NFT projects valued at more than US $100million
树形DP AcWing 285. 没有上司的舞会
14 check whether integers and their multiples exist
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
Ansible
背包问题 AcWing 9. 分组背包问题
Redis high availability principle
数字三角形模型 AcWing 275. 传纸条
Internal and external troubles of digital collection NFT "boring ape" bayc