当前位置: 首页 > news >正文

【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

【洛谷】AT_abc178_d [ABC178D] Redistribution 的题解

洛谷传送门

AT传送门

题解

一个水水的动态规划,阿巴巴巴。

题目大概是这样:

给定一个正整数 S S S,问有多少个数满足以下条件:

  • 序列中不能出现小于 3 3 3 的正整数。

  • 序列中的和必须等于输入的 S S S

这是一道求方案数的题,我们可以用动态规划来做,那么我们就可以定义 d p i dp_i dpi 为和为 i i i
时的方案数,然后我们就可以想到对于每一个 d p i dp_i dpi 它都等于从
i − 3 i−3 i3 3 3 3 的方案数总和加一,最后输出 f n f_n fn 即可。

最后提醒,AtCoder 输出要换行!!!

代码

#include <bits/stdc++.h>
#define lowbit(x) x & (-x)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
namespace fastIO {inline int read() {register int x = 0, f = 1;register char c = getchar();while (c < '0' || c > '9') {if(c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f;}inline void write(int x) {if(x < 0) putchar('-'), x = -x;if(x > 9) write(x / 10);putchar(x % 10 + '0');return;}
}
using namespace fastIO;
int n;
ll f[2005];
int main() {//freopen(".in","r",stdin);//freopen(".out","w",stdout);ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);n = read();for(int i = 3; i <= n; i ++) {f[i] = 1;for(int j = 3; j <= i - 3; j ++) {f[i] = (f[i] + f[j]) % mod;}	}cout << f[n] << endl;return 0;
}

http://www.mrgr.cn/news/37872.html

相关文章:

  • 手搓一个Agent#Datawhale 组队学习Task3
  • 1013. 将数组分成和相等的三个部分 数组切分
  • 物理学基础精解【30】
  • 用十万字解析《微积分(第三版)》
  • 如何注册和使用Disney+?Disney+会员账号可以合租?Disney+会员账号订阅购买使用教程
  • 并发编程---线程与进程
  • --杂项2--
  • ffmpeg 结合 opencv 显示ps流文件
  • MATLAB绘图基础9:多变量图形绘制
  • Android界面控件概述
  • 每日论文6—16ISCAS一种新型低电流失配和变化电流转向电荷泵
  • 算法学习3
  • 2024最新Linux Socket编程
  • 串匹配问题的三种算法
  • 大豆重测序-文献精读53
  • 树上差分详解
  • Java网络通信—UDP
  • 盘点2024年4款高效率的语音转文字工具。
  • 算法刷题笔记 约数个数(详细注释的C++实现)
  • MySQL 之索引详解