当前位置:网站首页>DP - [noip2000] grid access
DP - [noip2000] grid access
2022-04-23 14:13:00 【Stingy old Sao】
[NOIP2000] Take the number of squares
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
//
Space 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
//
版权声明
本文为[Stingy old Sao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231407093939.html
边栏推荐
- Request module
- On September 8, the night before going to Songshan Lake
- DDT+Excel进行接口测试
- 使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)
- On the problem of cliff growth of loss function in the process of training
- HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
- squid代理
- Some good articles on pthread multithreading
- 第四届“传智杯”全国大学生IT技能大赛(决赛B组) 题解
- win10自带Groove音乐不能播放CUE和APE文件的一种曲线救国办法,自己创建aimppack插件包,AIMP安装DSP插件
猜你喜欢
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
在MAC上安装mysql
squid代理
MYSQL 主从同步避坑版教程
PySide2
Visio installation error 1:1935 2: {XXXXXXXX
使用开源调研工具Prophet是一种什么体验?
openstack理论知识
redis数据库讲解二(redis高可用、持久化、性能管理)
随机推荐
jsp学习1
leetcode--977. Squares of a Sorted Array
Wechat applet obtains login user information, openid and access_ token
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
JDBC details
帆软实现分页时第一行和最后两行冻结方式
pthread_ Why does self() repeat
Use of WiFi module based on wechat applet
Switch usage (wechat applet)
星界边境文本自动翻译机使用说明
OpenStack命令操作
获取线程返回值Future接口与FutureTask类使用介绍
星界边境Starbound创意工坊订阅的mod的存放路径
Request module
openstack理论知识
教育行业云迁移最佳实践:海云捷迅使用HyperMotion云迁移产品为北京某大学实施渐进式迁移,成功率100%
Storage path of mod subscribed by starbound Creative Workshop at Star boundary
RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
redis数据库讲解二(redis高可用、持久化、性能管理)
On the problem of cliff growth of loss function in the process of training