转化一下,相当于从$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. HttpClientUntils工具类的使用测试及注意事项(包括我改进的工具类和Controller端的注意事项【附 Json 工具类】)

    HttpClient工具类(我改过): package com.taotao.httpclient; import java.io.IOException; import java.net.URI; ...

  2. ubunut14.04 mentohust配置

      1.设置网卡eth0的IP地址和子网掩码 sudo ifconfig eth0 10.162.32.94 netmask 255.0.0.0 将IP地址改为:10.162.32.94,子网掩码改为 ...

  3. Spring学习--依赖注入的方式

    Spring 依赖注入: 属性注入(最常使用) 构造函数注入 工厂方法注入(很少使用,不推荐) 属性注入:通过 setter 方法注入 Bean 的属性值或依赖的对象 , 使用<property ...

  4. P3076 [USACO13FEB]出租车Taxi

    题目描述 Bessie is running a taxi service for the other cows on the farm. The cows have been gathering a ...

  5. Shell之基本用法

    一:shell简介 1.什么是shell shell的中文意思是“外壳”,通俗地讲,shell是一个交互编程接口,通过获得用户输入来驱动操作系统内核完成指定工作.shell除了作为命令解释程序以外,还 ...

  6. Flink源码阅读(一)--Checkpoint触发机制

    Checkpoint触发机制 Flink的checkpoint是通过定时器周期性触发的.checkpoint触发最关键的类是CheckpointCoordinator,称它为检查点协调器. org.a ...

  7. 【hdu1251-统计难题】Trie

    http://acm.hust.edu.cn/vjudge/problem/16379 题意:给定多个单词,多次询问符合某前缀的单词有多少个. 题解:tire.数组开了5*10^6才A,不然就RE. ...

  8. 通过 CLI 搭建 ghost

    参考: ghost 官网 系统架构说明 架构 架构说明 本实践将 web 接入, nodejs 服务, 数据库分离, 适合生产环境场景. nginx 接入请求, 反向代理后端 nodejs 服务 no ...

  9. 我喜欢的4个VS扩展吧

    原文发布时间为:2011-06-09 -- 来源于本人的百度文章 [由搬家工具导入]

  10. PHP HERE DOCUMENT

    转自: http://www.codeweblog.com/php%E4%B8%ADheredoc%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95/ Here ...