当前位置:网站首页>Digital triangle model acwing 275. pass note
Digital triangle model acwing 275. pass note
2022-07-27 11:13:00 【T_ Y_ F666】
Digital triangle model AcWing 275. Pass slip
Original link
Algorithm tags
Dynamic programming linear DP
Ideas

Optimization of row number value range

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];
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(),m=read();
rep(i, 1, n+1){
rep(j, 1, m+1){
a[i][j]=read();
}
}
// Sum of row and column values The row determines the column
rep(k, 2, n+m+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<=m&&j2>=1&&j2<=m){
int t=a[i1][j1];
if(i1-i2){
t+=a[i2][j2];
}
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[n+m][n][n]);
return 0;
}
Line number value range optimization 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];
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(),m=read();
rep(i, 1, n+1){
rep(j, 1, m+1){
a[i][j]=read();
}
}
// Sum of row and column values The row determines the column
rep(k, 2, n+m+1){
// First time i That's ok
rep(i1, max(1ll, k-m), min(k, n)+1){
// Second time i That's ok
rep(i2, max(1ll, k-m), min(k, n)+1){
// k-i1 Indicates the number of columns for the first time k-i2 Indicates the number of secondary columns
int t=a[i1][k-i1];
if(i1-i2){
t+=a[i2][k-i2];
}
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[n+m][n][n]);
return 0;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
- ethereum rpc
- NFT leaderboard -nft real offer latest address: NFT leaderboard.com
- Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
- 10 complete half of the questions
- Review and Prospect of encrypted traffic identification based on deep learning
- Integrated design of communication perception based on CSI: problems, challenges and Prospects
- Taishan Office Technology Lecture: scaling and opening files
- 【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
- Maximized array sum after 13 K negations
猜你喜欢

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

Symmetric encryption and asymmetric encryption

Use__ slots__ And__ dict__ To save space (it's simply a qualitative leap, and leetcode's personal test is effective)

迭代次数的差异与信息熵

How to modify the strict mode under MySQL so that adding new users by inserting user table is successful

Antd table+checkbox default value display

antd table+checkbox 默认值显示

SQL Server2000数据库错误

发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析

Shortest moving distance and entropy of morphological complex
随机推荐
What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
The influence of the number of non-zero values in the picture on Classification
最短移动距离和形态复合体的熵
迭代次数和熵之间关系的一个验证试验
正则form表单判断
Verilog implementation of ECG signal acquisition, storage and transmission system based on FPGA
Play with the cluster configuration center and learn about the Taier console
The article will not keep VIP charges all the time. It will be open for a period of time
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
Application scenarios, key technologies and network architecture of communication perception integration
TensorFlow张量运算函数集
如何组装一个注册中心
10 complete half of the questions
Detailed explanation of status code meaning
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
熵与形态的非递进现象
Analysis of C language pointer function and function pointer
antd table中排序th阻止悬停变色+table悬停行变色+table表头变色
SQL Server2000 database error
学习笔记-微信支付