当前位置:网站首页>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();
}
}
边栏推荐
猜你喜欢

MySQL连接时出现2003错误

Detailed explanation of the delete problem of ClickHouse delete data

通过社交媒体建立个人IP的 5 种行之有效的策略

The Road to Ad Monetization for Uni-app Mini Program Apps: Rewarded Video Ads

反转链表-就地逆置法

宁波中宁典当转让29.5%股权为283.38万元,2021年所有者权益为968.75万元

Excel基础学习笔记

Py之pdpbox:pdpbox的简介、安装、案例应用之详细攻略

MySQL 5.7详细下载安装配置教程

win10重建索引
随机推荐
reindex win10
OpenCV笔记(二十):滤波函数——filter2D
【云驻共创】HCSD大咖直播–就业指南
Ningbo Zhongning Pawn will transfer 29.5% of the equity for 2.8338 million yuan, and the owner's equity in 2021 will be 9.6875 million yuan
MYSQL JDBC图书管理系统
Regular expression syntax and usage
ClickHouse to create a database to create a table view dictionary SQL
IJCAI2022 Tutorial | Spoken Language Comprehension: Recent Advances and New Fields
CISP-PTE Zhenti Demonstration
2022.7.30
【Summary】机器人方法汇总
【无标题】
Be careful with your dictionaries and boilerplate code
反转链表-头插反转法
482-静态库、动态库的制作、使用及区别
MySQL联合查询(多表查询)
QT 在父类中添加子类的流程,object tree,
连号区间数
MySql 5.7.38 download and installation tutorial, and realize the operation of MySql in Navicat
鳄梨价格数据集(Avocado Prices)