当前位置:网站首页>AtCoder Beginner Contest 237 VP补题
AtCoder Beginner Contest 237 VP补题
2022-07-02 15:15:00 【sophilex】
大意:
给定一张无向图,两点间的边权:
较高点到较低点的边权等于高度差
较低点到较高点的边权等于高度差的负二倍
求:图中的最大dis值
思路:
按题意建边即可;
但是有负权,所以一般的dij不行。
赛后又加强过数据,所以我跑了spfa,T烂了。。。(但是我看有一个哥们还真用spfa冲过去了。。。【崩溃】)
官方题解的思路是dij
考虑“势”的思想(绝):
对数据进行预处理,高点到低点的边权等于0,低点到高点的距离等于高度差(>=0)
那么就全是非负权边了。
跑完dij后只要把数据还原回去就可以了,dis[i]=h[i]-h[1]+dist[i]
code:
再说
大意:
求长度为 n,每个元素不大于m的序列,满足以下条件的有多少种:
最长上升子序列长度恰好为3.
思路:
m很小,只有10,那么久很容易想到暴力枚举+dp
不妨设i代表当前枚举到的数列长度,k1 表示当前序列长度为1的LIS的最后一个元素的最小值,k2 表示当前序列长度为2的LIS的最后一个元素的最小值,k3 则表示当前序列长度为3的LIS的最后一个元素的最小值
那么dp[i][k1][k2][k3]就代表对应情况的方案数。
那么每次再多枚举一个x,对x的大小进行分类讨论即可。
细节见code:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll N=1005;
const ll mod=998244353;
ll dp[N][12][12][12];
ll n,m;
int main()
{
cin>>n>>m;
dp[0][m+1][m+1][m+1]=1;
for(int i=1;i<=n;++i)
{
for(int k1=1;k1<=m+1;++k1)
{
for(int k2=1;k2<=m+1;++k2)
{
for(int k3=1;k3<=m+1;++k3)
{
for(int x=1;x<=m;++x)
{
if(x<=k1) dp[i][x][k2][k3]=(dp[i-1][k1][k2][k3]+dp[i][x][k2][k3])%mod;
else if(x<=k2) dp[i][k1][x][k3]=(dp[i-1][k1][k2][k3]+dp[i][k1][x][k3])%mod;
else if(x<=k3) dp[i][k1][k2][x]=(dp[i-1][k1][k2][k3]+dp[i][k1][k2][x])%mod;
}
}
}
}
}
ll ans=0;
for(int k1=1;k1<=m;++k1)
{
for(int k2=1;k2<=m;++k2)
{
for(int k3=1;k3<=m;++k3)
{
// cout<<dp[n][k1][k2][k3];
ans=(ans+dp[n][k1][k2][k3])%mod;
}
}
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- Example nonlinear integer programming
- traceroute命令讲解
- 剑指 Offer 24. 反转链表
- 一年頂十年
- Update iteration of cloud communication interface -- the official launch of subail API V4
- PCL knowledge points - voxelized grid method for down sampling of point clouds
- 云通信接口更新迭代——SUBMAIL API V4正式上线
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
- Win10系统使用pip安装juypter notebook过程记录(安装在系统盘以外的盘)
- Sword finger offer 25 Merge two sorted linked lists
猜你喜欢
剑指 Offer 22. 链表中倒数第k个节点
剑指 Offer 26. 树的子结构
MATLAB中nexttile函数使用
Timing / counter of 32 and 51 single chip microcomputer
Does digicert SSL certificate support Chinese domain name application?
Experience home office, feel the completion of the project | community essay solicitation
綠竹生物沖刺港股:年期內虧損超5億 泰格醫藥與北京亦莊是股東
从收集到输出:盘点那些强大的知识管理工具——优秀笔记软件盘点(四)
Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
默认浏览器设置不了怎么办?
随机推荐
Niuke js3 separator
visibilitychange – 指定标签页可见时,刷新页面数据
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
剑指 Offer 26. 树的子结构
QWebEngineView崩溃及替代方案
常用SQL语句(完整范例)
Geoserver: publishing PostGIS data sources
Qwebengineview crash and alternatives
什么是敏捷开发流程
si446使用记录(二):使用WDS3生成头文件
Use the API port of the bridge of knowledge and action to provide resources for partners to access
Si446 usage record (II): generate header files using wds3
chrome浏览器快速访问stackoverflow
Chmod command principle and usage details [easy to understand]
2322. Remove the minimum fraction of edges from the tree (XOR and & Simulation)
How to transfer business data with BorgWarner through EDI?
Briefly introduce the use of base64encoder
Idea2021.1 installation tutorial
Five reasons to choose SAP Spartacus as the implementation framework of SAP commerce cloud storefront
链表求和[dummy+尾插法+函数处理链表引用常见坑位]