题面

传送门

Sol

有一个显然的想法

处理出\(y, z\)能凑出的高度

然后这些高度凑一些\(x\)就可以得到其它的高度

那么可以把这些\(y, z\)凑出的高度对\(x\)取模,其它的用\(x\)来填补

所以设\(f[i]\)表示\(y, z\)凑出高度\(\%x\)为\(i\)需要的最低高度

那么答案就是

\[\sum_{i=0}^{x-1}\lfloor\frac{(n-f[i])}{x}\rfloor+1
\]

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
const int _(1e5 + 5);
typedef long long ll; IL ll Input(){
RG ll x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int x, y, z, first[_], cnt, vis[_];
ll n, ans, f[_];
struct Edge{
int to, next, w;
} edge[_ << 1];
queue <int> Q; IL void Add(RG int u, RG int v, RG int w){
edge[cnt] = (Edge){v, first[u], w}, first[u] = cnt++;
} int main(RG int argc, RG char* argv[]){
n = Input(), x = Input(), y = Input(), z = Input();
if(y < x) swap(x, y);
if(z < x) swap(x, z);
for(RG int i = 0; i < x; ++i) first[i] = -1;
for(RG int i = 0; i < x; ++i) Add(i, (i + y) % x, y), Add(i, (i + z) % x, z);
Fill(f, 127), f[1 % x] = 1, vis[1 % x] = 1, Q.push(1 % x);
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
for(RG int e = first[u]; e != -1; e = edge[e].next){
RG int v = edge[e].to, w = edge[e].w;
if(f[u] + w < f[v]){
f[v] = f[u] + w;
if(!vis[v]) vis[v] = 1, Q.push(v);
}
}
vis[u] = 0;
}
for(RG int i = 0; i < x; ++i) if(f[i] <= n) ans += (n - f[i]) / x + 1;
return printf("%lld\n", ans), 0;
}

最新文章

  1. Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用(后续)
  2. XStream学习笔记
  3. 自己写的一个简单的jQuery提示插件
  4. Android几种打开SQLite的方法
  5. CSS3中的animation动画
  6. &lt;&lt;卸甲笔记&gt;&gt;-Oracle线下迁移到PPAS
  7. HTML5和css3的总结
  8. wordpress 提取头像的src
  9. Http协议与TCP协议理解
  10. 安卓Eclipse开发者的福音
  11. .Net中World转PDF
  12. 算法: 包含min函数的栈
  13. 优化CSS重排重绘与浏览器性能
  14. Scrapy基础02
  15. Ubuntu18系统qt生成程序无法双击运行问题
  16. Python 进行查询日志查询条件分析
  17. 第15月第22天 libz.dylib
  18. jsp中的include静态包含与动态包含,
  19. JavaScript计算指定日期与当前日期的相差天数
  20. Touchmove获取当前触摸的Dom节点

热门文章

  1. 题目1042:Coincidence(最长公共子序列)
  2. Java非静态代码块和静态代码块
  3. UBoot常用命令及内核下载与引导
  4. chromedriver for mac
  5. readonly与disable
  6. am335x uboot启动流程分析
  7. this和target目标对象的区别
  8. SVM面经
  9. How do I use screen on the Linux systems?
  10. input标签的按钮效果