当前位置:网站首页>2021GDCPC广东省大学生程序设计竞赛 H.History
2021GDCPC广东省大学生程序设计竞赛 H.History
2022-07-30 22:48:00 【_Kiwi_Berry_】
题意:
给定一个由n个点,m条边组成的图,每走一步,所有边权都会按以下公式变换
求1到n的最短路
思路:
如果每次都变换成不同的,namo这题感觉不太可做,但连续代入几次后发现,这是个周期为4的循环,故可以用分层图做
我们可以一开始建好四层图,也可以先存边在dij函数内求不同层之间的距离,这里我用了第二种方法
Code:
#include <bits/stdc++.h>
// #define debug freopen("_in.txt", "r", stdin);
#define debug freopen("_in.txt", "r", stdin), freopen("_out.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
typedef struct Node *bintree;
using namespace std;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll maxn = 1e7 + 10;
const ll maxm = 2e6 + 10;
const ll mod = 998244353;
const double pi = acos(-1);
const double eps = 1e-8;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
ll T, n, m, q, d, kase = 0;
priority_queue<pair<ll, ll>> que;
ll arr[100];
ll dp[3][maxn];
void solve()
{
scanf("%lld", &n);
printf("%lld\n",(dp[0][n]+dp[1][n])%mod);
}
signed main()
{
// debug;
scanf("%lld", &T);
// T = 1;
arr[1] = arr[2] = 1;
for (ll i = 2; i <= 50; i++)
{
arr[i] = arr[i - 1] + arr[i - 2];
}
dp[0][0] = 1;
dp[0][1] = 1;
dp[1][1] = 1;
ll now = 0;
for (ll i = 2; i <= 1e7; i++)
{
if (i >= arr[now])
{
while (i >= arr[now])
{
now++;
}
now--;
}
ll v1=arr[now],v2=arr[now-1];
dp[0][i]=(dp[0][i-v1]+dp[1][i-v1])*v1;
dp[0][i]%=mod;
if(i-v2<v2)
{
dp[1][i]=(dp[0][i-v2]+dp[1][i-v2])*v2;
}
else
{
dp[1][i]=(dp[1][i-v2])*v2;
}
dp[1][i]%=mod;
}
while (T--)
{
solve();
}
}
边栏推荐
猜你喜欢

TCP 连接 三次握手 四次挥手

ML's shap: Based on FIFA 2018 Statistics (2018 Russia World Cup) team match star classification prediction data set using RF random forest + calculating SHAP value single-sample force map/dependency c

PhpMetrics usage

A detailed explanation: SRv6 Policy model, calculation and drainage

Abstract classes and interfaces (study notes)
![[MySQL] Mysql transaction and authority management](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[MySQL] Mysql transaction and authority management

VS2017编译Tars测试工程

MySQL 8.0.29 解压版安装教程(亲测有效)

MySQL连接时出现2003错误

Gxlcms audio novel system/novel listening system source code
随机推荐
WSL安装图形界面并通过xrdp/X-Launch访问
MySQL compressed package installation, fool teaching
d使用among的问题
2022/07/30 学习笔记 (day20) 面试题积累
关于XML的学习(一)
grub 学习
482-静态库、动态库的制作、使用及区别
The problem of sticky packets in tcp protocol transmission
【高等数学】矩阵与向量组的秩和等价
Detailed operator
Go语学习笔记 - gorm使用 - gorm处理错误 Web框架Gin(十)
QT开发简介、命名规范、signal&slot信号槽
史上最全的Redis基础+进阶项目实战总结笔记
Apache Doris系列之:深入认识实时分析型数据库Apache Doris
cnpm的安装与使用
MySQL进阶sql性能分析
tcp协议传输中的粘包问题
Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
The Road to Ad Monetization for Uni-app Mini Program Apps: Rewarded Video Ads
openim支持十万超级大群