转化一下,相当于从$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的更多相关文章

  1. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  2. 洛谷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 ...

  3. [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 ...

  4. LeetCode Coin Change

    原题链接在这里:https://leetcode.com/problems/coin-change/ 题目: You are given coins of different denomination ...

  5. ACM Coin Test

    Coin Test 时间限制:3000 ms  |  内存限制:65535 KB 难度:1   描述 As is known to all,if you throw a coin up and let ...

  6. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. leetcode:Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  8. UVa 674 Coin Change【记忆化搜索】

    题意:给出1,5,10,25,50五种硬币,再给出n,问有多少种不同的方案能够凑齐n 自己写的时候写出来方案数老是更少(用的一维的) 后来搜题解发现,要用二维的来写 http://blog.csdn. ...

  9. Epic - Coin Change

    Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most eff ...

随机推荐

  1. 面试前需要弄懂的SQL

    说明:创建数据库 view source   print? 1 Create DATABASE database-name 说明:删除数据库 view source   print? 1 drop d ...

  2. taotao单点登录的用户Controller、service(注册、登录、验证是否登录方法)

    接口文档: 1.1. 注册接口 1.1.1. 检查数据是否可用 请求方法 GET URL http://sso.taotao.com/user/check/{param}/{type} 参数说明 格式 ...

  3. github导入springboot maven项目

    1.在GitHub里force喜欢的项目,获取GitHub项目地址,eclipse---import---project from git---clone uri---next---finish,项目 ...

  4. bzoj 2304 [Apio2011]寻路 Dij+模拟+恶心建图

    [Apio2011]寻路 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 624  Solved: 193[Submit][Status][Discus ...

  5. 一个IT中专生在深圳的9年辛酸经历

    一个IT中专生在深圳的9年辛酸经历 想一想来到深圳已经近10年了,感概万千呐!从一个身无分文的中专职校计算机毕业出来后,竟然大胆的南下(之前可是连我们那地区之外都没去过),现在有供完的房子,温柔的妻子 ...

  6. netty入门代码学习

    服务端代码: package com.lsp.netty; /** * @author lishupeng * @create 2017-05-27 下午 3:48 **/ import io.net ...

  7. LeetCode the longest palindrome substring

    回文检测,参考http://blog.csdn.net/feliciafay/article/details/16984031 使用时间复杂度和空间复杂度相对较低的动态规划法来检测,具体的做法 图一 ...

  8. Swift : missing argument label 'xxx' in call

    http://stackoverflow.com/questions/24050844/swift-missing-argument-label-xxx-in-call up vote37down v ...

  9. Kuangbin 带你飞 最小生成树题解

    整套题都没什么难度. POJ 1251 Jungle Roads #include <map> #include <set> #include <list> #in ...

  10. UVALIVE 3562 Remember the A La Mode!

    费用流 建图很简单直接上代码 #include <map> #include <set> #include <list> #include <cmath> ...