当前位置:网站首页>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();
}
}
边栏推荐
猜你喜欢
随机推荐
ClickHouse to create a database to create a table view dictionary SQL
使用LVS和Keepalived搭建高可用负载均衡服务器集群
MySql 5.7.38下载安装教程 ,并实现在Navicat操作MySql
打动中产精英群体,全新红旗H5用产品力跑赢需求
Be careful with your dictionaries and boilerplate code
cnpm安装步骤
openim支持十万超级大群
TCP 连接 三次握手 四次挥手
IDEA 连接 数据库
WSL2设置默认启动用户(debian)
cmd (command line) to operate or connect to the mysql database, and to create databases and tables
2022.7.27
2sk2225代换3A/1500V中文资料【PDF数据手册】
The most powerful and most commonly used SQL statements in history
mysql跨库关联查询(dblink)
MySQL 8.0.29 set and modify the default password
WSL安装图形界面并通过xrdp/X-Launch访问
QT开发简介、命名规范、signal&slot信号槽
MySQL进阶sql性能分析
Apache Doris系列之:安装与部署详细步骤