题目:1015. 摘花生
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int >PII;
const int N=(1<<11)+10;
const int mod=1e9+7;
int t,r,c;
int a[110][110];
int main() {
cin>>t;
while(t--){
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
a[i][j]+=max(a[i-1][j],a[i][j-1]);
}
}
cout<<a[r][c]<<endl;
}
return 0;
}
题目:1018. 最低通行费
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int >PII;
const int N=(1<<11)+10;
const int mod=1e9+7;
int t,r,c;
int a[110][110];
int main() {
cin>>t;
for(int i=1;i<=t;i++){
for(int j=1;j<=t;j++){
cin>>a[i][j];
}
}
for(int i=0;i<=t;i++)
a[i][0]=a[0][i]=1001000;
a[0][1]=0;
for(int i=1;i<=t;i++){
for(int j=1;j<=t;j++){
a[i][j]+=min(a[i-1][j],a[i][j-1]);
}
}
cout<<a[t][t];
return 0;
}
题目:1027. 方格取数
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int >PII;
const int N=(1<<11)+10;
const int mod=1e9+7;
int n;
LL a[15][15],f[25][15][15];
int main() {
cin>>n;
int x,y,z;
while(cin>>x>>y>>z){
if(x==0&&y==0){
break;
}
a[x][y]=z;
}
for(int k=2;k<=2*n;k++){
for(int i=1;i<=n&&i<k;i++){
for(int j=1;j<=n&&j<k;j++){
LL t=a[i][k-i];
if(i!=j) t+=a[j][k-j];
f[k][i][j]=max(f[k][i][j],f[k-1][i-1][j-1]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i-1][j]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i][j-1]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i][j]+t);
}
}
}
printf("%lld",f[2*n][n][n]);
return 0;
}
题目:275. 传纸条
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int ,int >PII;
const int N=(1<<11)+10;
const int mod=1e9+7;
int n,m;
LL a[55][55],f[110][55][55];
int main() {
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
for(int k=2;k<=n+m;k++){
for(int i=1;i<=n&&i<k;i++){
for(int j=1;j<=n&&j<k;j++){
LL t=a[i][k-i];
if(i!=j)t+=a[j][k-j];
f[k][i][j]=max(f[k][i][j],f[k-1][i-1][j-1]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i-1][j]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i][j-1]+t);
f[k][i][j]=max(f[k][i][j],f[k-1][i][j]+t);
}
}
}
printf("%lld",f[m+n][n][n]);
return 0;
}