当前位置:网站首页>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();
}
}
边栏推荐
- 史上最全的Redis基础+进阶项目实战总结笔记
- mysql跨库关联查询(dblink)
- ZZULIOJ:1119: 数列有序
- Debezium报错系列之二十:task failed to create new topic.Ensure that the task is authorized to create topics
- 通过社交媒体建立个人IP的 5 种行之有效的策略
- 【导航规划】导航规划背景知识总结
- Go语学习笔记 - gorm使用 - 表增删改查 Web框架Gin(八)
- 成功解决ModuleNotFoundError: No module named ‘Image‘
- ZZULIOJ:1120: 最值交换
- MySQL 8.0.29 set and modify the default password
猜你喜欢

MySQL compressed package installation, fool teaching

When Navicat connects to MySQL, it pops up: 1045: Access denied for user 'root'@'localhost'

IJCAI2022教程 | 口语语言理解:最新进展和新领域

WSL安装图形界面并通过xrdp/X-Launch访问

cookie和session区别

EasyExcel综合课程实战

@RequestBody、 @RequestParam 、 @PathVariable 和 @Vaild 注解

阿里云视频点播+项目实战
![[MySQL] DQL related operations](/img/a5/c92e0404c6a970a62595bc7a3b68cd.gif)
[MySQL] DQL related operations

【导航规划】导航规划背景知识总结
随机推荐
cnpm安装步骤
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
Solve npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead
proxy反向代理
通过对抗性知识蒸馏压缩深度图神经网络
力扣题(3)—— 无重复字符的最长子串
反转链表-头插反转法
【微信小程序】小程序突破小程序二维码数量限制
基于 Docker Compose 的 Nacos(MySQL 持久化)的搭建
鳄梨价格数据集(Avocado Prices)
ZZULIOJ:1119: 数列有序
mysql remove duplicate data
Gxlcms audio novel system/novel listening system source code
反转链表-就地逆置法
Go的Gin框架学习
【导航规划】导航规划背景知识总结
The most powerful and most commonly used SQL statements in history
Rust编译报错:error: linker `cc` not found
tcp协议传输中的粘包问题
Go1.18升级功能 - 泛型 从零开始Go语言