[Contest20180328]coin
转化一下,相当于从$0$跳到$M$,每一步跳跃距离为$v_i$中的某个,每次跳跃距离不大于上一次,统计方案数
用$f_{i,j,k}$表示跳到$i$,第一步跳$v_j$,最后一步跳$\geq v_k$的方案数,那么有转移$f_{a+b,i,j}=\sum\limits_{k=1}^nf_{a,i,k}f_{b,k,j}$,跟矩阵乘法一模一样,所以我们可以把每个$f_i$看成矩阵,用矩阵乘法转移
先预处理出$f_{v_{1\cdots n}}$,显然$f_{v_1,1,1}=1,f_{v_1,i,j}=0$,然后有$f_{v_i}=f_{v_{i-1}}^{\frac{v_i}{v_{i-1}}}+A_i$(其中$A_i$的第$i$行的前$i$位是$1$,其它位置是$0$)因为$v_i$是$v_{i-1}$的倍数,再加上从起点一步跳到$v_i$这种方法,所以有这样的转移
最后来统计答案,也就是计算$f_M$,直接从$v_n$到$v_1$贪心地取转移就好了
为什么?假如有这样一种贪心跳法:一直跳$v_n$直到不能跳,然后跳$v_{n-1}$,以此类推,假设它经过的点叫做“关键点”,那么关键点一定被所有不同的跳法所经过,因为这些跳法都是把贪心跳法中的大步换成小步得到的($v_i$中两两互为倍数或因数),这样就说明了以上计算$f_M$的方法是正确的
#include<stdio.h> #include<string.h> const int mod=998244353; typedef long long ll; int mul(int a,int b){return a*(ll)b%mod;} int ad(int a,int b){return(a+b)%mod;} int n; struct matrix{ int a[51][51]; matrix(){memset(a,0,sizeof(a));} }t[51],ans; matrix operator*(matrix a,matrix b){ int i,j,k; matrix c; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ for(k=1;k<=n;k++)c.a[i][j]=ad(c.a[i][j],mul(a.a[i][k],b.a[k][j])); } } return c; } matrix pow(matrix a,ll b){ matrix s; for(int i=1;i<=n;i++)s.a[i][i]=1; while(b){ if(b&1)s=s*a; a=a*a; b>>=1; } return s; } ll v[51]; int main(){ ll m,k; int i,j; scanf("%d%lld",&n,&m); for(i=1;i<=n;i++)scanf("%lld",v+i); t[1].a[1][1]=1; for(i=2;i<=n;i++){ k=v[i]/v[i-1]; t[i]=pow(t[i-1],k); for(j=1;j<=i;j++)t[i].a[i][j]++; } for(i=1;i<=n;i++)ans.a[i][i]=1; for(i=n;i>0;i--){ k=m/v[i]; m%=v[i]; ans=ans*pow(t[i],k); } k=0; for(i=1;i<=n;i++)k=ad(k,ans.a[i][1]); printf("%lld",k); }
[Contest20180328]coin的更多相关文章
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- 洛谷P2964 [USACO09NOV]硬币的游戏A Coin Game
题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...
- [luogu2964][USACO09NOV][硬币的游戏A Coin Game] (博弈+动态规划)
题目描述 Farmer John's cows like to play coin games so FJ has invented with a new two-player coin game c ...
- LeetCode Coin Change
原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...
- ACM Coin Test
Coin Test 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 As is known to all,if you throw a coin up and let ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- leetcode:Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function ...
- UVa 674 Coin Change【记忆化搜索】
题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...
- Epic - Coin Change
Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...
随机推荐
- linux 条件判断式
1.利用if ...then if [ 判断条件 ];then 指令 fi 实例一 Y/N: #!/bin/bash #Program: # This program shows "Hell ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- springboot搭建web项目(转)
转:http://blog.csdn.net/linzhiqiang0316/article/details/52589789 这几天一直在研究IDEA上面怎么搭建一个web-mvc的SpringBo ...
- bzoj 2756 [SCOI2012]奇怪的游戏 二分+网络流
2756:[SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 4926 Solved: 1362[Submit][Stat ...
- ansible 批量修改root密码
[root@sz_fy_virt_encrypt_33_239 fetch]# cat /opt/passwd.yml - hosts: web vars: path: /home/opsadmin ...
- maven2应用之jar插件使用介绍
[转载声明] 转载时必须标注:本文来源于铁木箱子的博客http://www.mzone.cc [本文地址] 本文永久地址是:http://www.mzone.cc/article/236.html 有 ...
- c++对拍实现
直接上代码吧. #include<bits/stdc++.h> using namespace std; int main(){ while(1){ system("./cute ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- jetty bleed漏洞利用工具
两个exp: https://github.com/AppSecConsulting/Pentest-Tools/blob/master/jetty-bleed.py https://github.c ...
- GitLab版本管理【转】
转自:http://www.cnblogs.com/wintersun/p/3930900.html GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目 ...