Div 2 536

E

傻逼DP直接做

我居然调了1.5h

我真的是太菜了.jpg

堆+扫描线直接维护每个位置的贪心结果

然后要么使用干扰

要么就接受贪心的结果

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
#define M 205
#define ll long long
int n,m,K,p[N];ll f[N][M];
struct node{int s,t,d,w;}a[N];
bool cmp(const node &a,const node &b){return a.s==b.s?a.t<b.t:a.s<b.s;}
priority_queue<pair<pair<int ,int > ,int > >q;
int main()
{
scanf("%d%d%d",&n,&m,&K);memset(f,0x3f,sizeof(f));
for(int i=1;i<=K;i++)scanf("%d%d%d%d",&a[i].s,&a[i].t,&a[i].d,&a[i].w);sort(a+1,a+K+1,cmp);
for(int i=1,j=1;i<=n;i++)
{
while(a[j].s<=i&&j<=K)q.push(make_pair(make_pair(a[j].w,a[j].d),j)),j++;
while(!q.empty()&&a[q.top().second].t<i)q.pop();
if(!q.empty())p[i]=q.top().second;
}
f[1][0]=0;
for(int i=1;i<=n;i++)
for(int j=0;j<=m;j++)
{
int x=p[i];
f[i+1][j+1]=min(f[i][j],f[i+1][j+1]);
if(x)f[a[x].d+1][j]=min(f[i][j]+a[x].w,f[a[x].d+1][j]);
else f[i+1][j]=min(f[i][j],f[i+1][j]);
}
ll ans=1ll<<60;
for(int i=0;i<=m;i++)ans=min(ans,f[n+1][i]);
printf("%lld\n",ans);
}

F

  • 这不是一个特征多项式优化常系数线性齐次递推裸题嘛!

然后我就开始写了...

然后我发现我不会求$K$次剩余...

然后我就GG了...

所以这个题不用会求$K$次剩余...

那么根据原根的性质,我们可以发现,$K$次剩余可以表达为$\frac{q}{p} \mod 998244352$的形式,其中$q$表达为$m = 3^q \mod 998244353$,$p=k$

如果$K$不存在逆元的话,就没有对应的$K$次剩余...

然后,就可以通过BSGS+exgcd求

所以矩阵乘法就能做的题,为啥我要用特征多项式啊!!!!!

附上代码:

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <bitset>
#include <map>
using namespace std;
#define N 205
#define ll long long
#define mod 998244353
#define mmod 998244352
int a[N],b[N],mo[N],tmp[N],n,k,m,ans;
int q_pow(int x,int n){int ret=1;for(;n;n>>=1,x=(ll)x*x%mod)if(n&1)ret=(ll)ret*x%mod;return ret;}
void mul(int *a,int *b,int *ret)
{
memset(tmp,0,sizeof(tmp));
for(int i=0;i<k;i++)
for(int j=0;j<k;j++)
tmp[i+j]=(tmp[i+j]+(ll)a[i]*b[j])%mmod;
for(int i=(k<<1)-2;i>=k;i--)if(tmp[i])for(int j=1;j<=k;j++)
tmp[i-j]=(tmp[i-j]-(ll)tmp[i]*mo[k-j])%mmod;
for(int i=0;i<k;i++)ret[i]=tmp[i];
}
map<int ,int >mp;
int ex_gcd(int a,int b,int &x,int &y)
{
if(!b)return x=1,y=0,a;int ret=ex_gcd(b,a%b,y,x);
y=y-a/b*x;return ret;
}
int BSGS(int x)
{
int s=5000,t=1;
for(int i=0;i<s;i++)mp[int((ll)t*x%mod)]=i,t=t*3ll%mod;
for(int i=1,now=1;;i++)
{
now=(ll)now*t%mod;
if(mp.find(now)!=mp.end())return i*s-mp[now];
}
}
int main()
{
scanf("%d",&k);
for(int i=1;i<=k;i++)scanf("%d",&mo[k-i]),mo[k-i]=mmod-mo[k-i];
scanf("%d%d",&n,&m);b[1]=1;a[0]=1;
if(k==1)b[0]=mmod-mo[0],b[1]=0;
for(n--;n;n>>=1){if(n&1)mul(a,b,a);mul(b,b,b);}
int t=(a[k-1]+mmod)%mmod,x=0,y=0;
int tt=ex_gcd(t,mmod,x,y),kk=BSGS(m);
if(kk%tt)return puts("-1"),0;
x=((ll)x*(kk/tt)%mmod+mmod)%mmod;
printf("%d\n",q_pow(3,x));
}

Codeforces round 1106的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. tilestache + mbutil应用

    1. 安装pip. 我们同样需要在Python的官网上去下载,下载地址是: https://pypi.python.org/pypi/pip#downloads 2. 解压. 解压pip-9.0.1. ...

  2. RaPC栅格化多边形裁剪之——进化0.1

    采用整数二维数组进行cell的归属标记,将所有符合条件的cell输出,不进行整体多边形重构,用以统计面积. 上图: INTERSECT: 网格区域为离散化的空间范围,黄色部分为求交结果. differ ...

  3. Android--WebView 自适应代码

    //WebView自适应代码 private String getHtmlData(String bodyHTML) { String head = "<head>" ...

  4. Debian 常用命令

    换源 用中科大的比较快 deb http://mirrors.ustc.edu.cn/debian jessie main contrib non-free deb-src http://mirror ...

  5. git中设置代理,本地不使用代理,针对域名设置代理

    想要的效果是: [1]本地IP不使用代理 [2]外网的仓库(如GitHub)使用代理 [3]适用于全局 方案 打开路径: C --> 用户 --> [我的账号] --> .gitco ...

  6. python的类基础

    python类的基础: 1,面向对象的基本概念 类(Class): 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 类变量:类变量在整个实例化的 ...

  7. C#多线程的用法10-线程池

    TheadPool:在进行多线程编程时,如果不想频繁的创建线程,那可以考虑使用使用线程池来完成多线程编程的工作.你只需将要处理的任务交付给ThreadPool,如果ThreadPool中有空闲的线程, ...

  8. Spring中的destroy-method方法

    1. Bean标签的destroy-method方法 配置数据源的时候,会有一个destroy-method方法 <bean id = "dataSource" class  ...

  9. Netstat Commands for Linux Network Management

    netstat (network statistics) is a command line tool for monitoring network connections both incoming ...

  10. tidb导入大量数据报错:statement count 5001 exceeds the transaction limitation, autocommit = false

    这是Tidb数据库事务提交数量达到上限的一种报错:因为tidb是分布式的数据库,tikv使用了底层的强一致性协议.这是分布式数据库必然遇到的一个问题,我们可以调整这个值:在tidb的配置文件里面“st ...