当前位置:网站首页>dp-[NOIP2000]方格取数
dp-[NOIP2000]方格取数
2022-04-23 14:08:00 【抠脚老騷】
[NOIP2000]方格取数
n^4
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];
void solve() {
int n;
cin >> n;
int x, y, w;
while ((cin >> x >> y >> w)&&!(x==0&&y==0&&w==0))a[x][y] = w;
dp[1][1][1][1] = a[1][1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= n; k++)
for (int g = 1; g <= n; g++) {
// if (i + j != k + g) continue;
int ans = a[i][j] + a[k][g];
if (i == k && j == g) ans /=2;
dp[i][j][k][g] = max(dp[i][j][k][g], dp[i - 1][j][k - 1][g] + ans);
dp[i][j][k][g] = max(dp[i][j][k][g], dp[i][j - 1][k - 1][g] + ans);
dp[i][j][k][g] = max(dp[i][j][k][g], dp[i - 1][j][k][g - 1] + ans);
dp[i][j][k][g] = max(dp[i][j][k][g], dp[i][j - 1][k][g - 1] + ans);
// cout<<dp[i][j][k][g]<<endl;
}
cout << dp[n][n][n][n];
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
n^3
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];
void solve() {
int n;
cin >> n;
int x, y, w;
while ((cin >> x >> y >> w)&&!(x==0&&y==0&&w==0))a[x][y] = w;
dp[2][1][1] = a[1][1];
for (int i = 2; i <= 2*n; i++)
for (int k = 1; k <= n; k++)
for (int g = 1; g <= n; g++) {
int x1=k,x2=g,y1=i-k,y2=i-g;
int ans=a[x1][y1]+a[x2][y2];
if(x1==x2&&y1==y2) ans/=2;
dp[i][k][g]= max(dp[i][k][g],ans+dp[i-1][x1-1][x2]);
dp[i][k][g]= max(dp[i][k][g],ans+dp[i-1][x1][x2-1]);
dp[i][k][g]= max(dp[i][k][g],ans+dp[i-1][x1][x2]);
dp[i][k][g]= max(dp[i][k][g],ans+dp[i-1][x1-1][x2-1]);
}
cout << dp[2*n][n][n];
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
空间n^2
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn];
int a[maxn][maxn];
int v[maxn];
void solve() {
int n;
cin >> n;
int x, y, w;
while ((cin >> x >> y >> w)&&!(x==0&&y==0&&w==0))a[x][y] = w;
for (int i = 2; i <= 2*n; i++)
for (int k=i; k>0; k--)
for (int g=i; g>0; g--) {
int x1=k,x2=g,y1=i-k,y2=i-g;
int ans=a[x1][y1]+a[x2][y2];
if(x1==x2&&y1==y2) ans/=2;
dp[k][g]=max(max(dp[k-1][g],dp[k][g-1]),max(dp[k-1][g-1],dp[k][g]))+ans;
// cout<<dp[k][g]<<endl;
}
cout << dp[n][n];
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
版权声明
本文为[抠脚老騷]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45436102/article/details/123998306
边栏推荐
- Redis数据库讲解(一)
- jsp学习1
- 线程间控制之Semaphore使用介绍
- Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
- ActiveMQ Basics
- FBS (fman build system) packaging
- Can I compile the header file and source file of the template separately
- Intégration de Clusters CDH Phoenix basée sur la gestion cm
- GFS分布式文件系统(理论)
- Chapter I review of e-commerce spike products
猜你喜欢
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
Postman的安装使用及填坑心得
Wechat applet obtains login user information, openid and access_ token
VMware installation 64 bit XP Chinese tutorial
金融行业云迁移实践 平安金融云整合HyperMotion云迁移解决方案,为金融行业客户提供迁移服务
VMware 15pro mounts the hard disk of the real computer in the deepin system
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
RobotFramework 之 文件上传和下载
RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
快速安装mongodb
随机推荐
RobotFramework 之 公共变量
GFS分布式文件系统(理论)
Windos中安装labellmg教程
Wechat applet obtains login user information, openid and access_ token
帆软报表设置单元格填报以及根据值的大小进行排名方法
帆软实现一个单选按钮,可以统一设置其他单选按钮的选择状态
使用itextpdf实现截取pdf文档第几页到第几页,进行分片
FBS (fman build system) packaging
Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程
Check in system based on ibeacons
帆软之单元格部分字体变颜色
基於CM管理的CDH集群集成Phoenix
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
RobotFramework 之 文件上传和下载
On the problem of cliff growth of loss function in the process of training
帆软分割求解:一段字符串,只取其中某个字符(所需要的字段)
HyperMotion云迁移完成阿里云专有云产品生态集成认证
容灾有疑问?点这里
Prediction of tomorrow's trading limit of Low Frequency Quantization