YBTOJ:方程的解(组合数学)(插板法)

文章目录

  • 题目描述
  • 解析
  • 代码

题目描述

请添加图片描述

解析

第一感觉:啥都没感觉出来。。。
直接拿动态规划+高精做的
但是只能拿40
重新分析一下这道题:
g(x)首先可以拿快速幂很容易的求出来
问题就转化为了**把g(x)个东西分成k份的方案数
其实答案就是C(k-1,n-1)
为什么是这样?
介绍一种新的方法:隔板法
本题画一下就是:
请添加图片描述
那么不难发现,一共有n-1个空隙,插入k-1个板(题目已经说明1,1,2和2,1,1是不一样的方案)
所以就可以得出组合数的结论了

代码

#include<iostream>
#include<cstdio>
#include<cstring>using namespace std;typedef long long ll;const int maxn = 1000;
const int BIT = 4;
const int MOD = 1e4;struct bign {int num[maxn], len;bool flag;friend bign abs(const bign &x) {bign k = x;k.flag = true;return k;}friend void remove(bign &x) {while (x.num[x.len] == 0 && x.len > 1)x.len--;}bign() {memset(num, 0, sizeof(num));flag = true;len = 1;}bign(const int &x) {*this = bign();if (x) {int k = x;if (k < 0)k = -k, flag = false;len = 0;while (k) {num[++len] = k % MOD;k /= MOD;}}}bign(const ll &x) {*this = bign();if (x) {ll k = x;if (k < 0)k = -k, flag = false;len = 0;while (k) {num[++len] = k % MOD;k /= MOD;}}}bign(const char *x) {int l = strlen(x), s, t = 0, p = 0, k = 1;*this = bign();if (x[0] == '-')flag = false, s = 1;len = 0;for (int i = l - 1; i >= s; i--) {p += k * (x[i] - '0');k *= 10;t++;if (t == 4) {t = 0;num[++len] = p;p = 0;k = 1;}}if (p)num[++len] = p;}bign(const string x) {int l = x.length(), s = 0, t = 0, p = 0, k = 1;*this = bign();if (x[0] == '-')flag = false, s = 1;len = 0;for (int i = l - 1; i >= s; i--) {p += k * (x[i] - '0');k *= 10;t++;if (t == BIT) {t = 0;num[++len] = p;p = 0;k = 1;}}if (p)num[++len] = p;}bign operator=(const int &x) {return *this = bign(x);}bign operator=(const ll &x) {return *this = bign(x);}bign operator=(const char *x) {return *this = bign(x);}bign operator=(const string &x) {return *this = bign(x);}bool operator<(const bign &x) const {if (flag != x.flag)return flag < x.flag;if (len != x.len)return (len < x.len) ^ flag ^ 1;for (int i = len; i >= 1; i--) {if (num[i] != x.num[i]) {return (num[i] < x.num[i]) ^ flag ^ 1;}}return false;}bool operator<(const int &x) const {return *this < bign(x);}bool operator<(const ll &x) const {return *this < bign(x);}bool operator>(const bign &x) const {return x < *this;}bool operator>(const int &x) const {return *this > bign(x);}bool operator>(const ll &x) const {return *this > bign(x);}bool operator<=(const bign &x) const {return !(*this > x);}bool operator<=(const int &x) const {return *this <= bign(x);}bool operator<=(const ll &x) const {return *this <= bign(x);}bool operator>=(const bign &x) const {return !(*this < x);}bool operator>=(const int &x) const {return *this >= bign(x);}bool operator>=(const ll &x) const {return *this >= bign(x);}bool operator==(const bign &x) const {if (flag != x.flag)return false;if (len != x.len)return false;for (int i = len; i >= 1; i--) {if (num[i] != x.num[i]) {return false;}}return true;}bool operator==(const int &x) const {return *this == bign(x);}bool operator==(const ll &x) const {return *this == bign(x);}bool operator!=(const bign &x) const {return !(*this == x);}bool operator!=(const int &x) const {return *this != bign(x);}bool operator!=(const ll &x) const {return *this != bign(x);}friend istream &operator>>(istream &in, bign &x) {string s;in >> s;x = s;return in;}friend ostream &operator<<(ostream &out, const bign &x) {if (x.flag == false && x != 0)out << "-";out << x.num[x.len];for (int i = x.len - 1; i >= 1; i--)printf("%0*d", BIT, x.num[i]);return out;}bign operator-() const {bign k = *this;k.flag ^= 1;return k;}bign operator+(const bign &x) const {if (flag && x.flag) {bign k = bign();k.len = 0;for (int i = 1, g = 0; g || i <= len || i <= x.len; i++) {int p = num[i] + x.num[i] + g;k.num[++k.len] = p % MOD;g = p / MOD;}return k;}if (flag && !x.flag)return *this - (-x);if (!flag && x.flag)return x - (-*this);return -((-x) + (-*this));}bign operator+(const int &x) const {return *this + bign(x);}bign operator+=(const bign &x) {return *this = *this + x;}bign operator+=(const int &x) {return *this += bign(x);}bign operator+=(const ll &x) {return *this += bign(x);}bign operator++() {return *this += 1;}bign operator++(int) {bign k = *this;*this += 1;return k;}bign operator-(const bign &x) const {if (flag && x.flag && *this >= x) {bign k = bign();k.len = 0;for (int i = 1, g = 0; g || i <= len; i++) {int p = num[i] - x.num[i] + g;if (p < 0)g = -1;else g = 0;k.num[++k.len] = (p % MOD + MOD) % MOD;}remove(k);return k;}if (flag && x.flag)return -(x - *this);if (flag && !x.flag)return *this + (-x);if (!flag && x.flag)return -((-*this) + x);return (-x) - (-*this);}bign operator-=(const bign &x) {*this = *this - x;return *this;}bign operator-=(const int &x) {return *this -= bign(x);}bign operator-=(const ll &x) {return *this -= bign(x);}bign operator--() {return *this -= 1;}bign operator--(int) {bign k = *this;*this -= 1;return k;}bign operator*(const bign &x) const {bign k;k.flag = (flag == x.flag);k.len = len + x.len + 1;for (int i = 1; i <= len; i++) {for (int j = 1; j <= x.len; j++) {k.num[i + j - 1] += num[i] * x.num[j];k.num[i + j] += k.num[i + j - 1] / MOD;k.num[i + j - 1] %= MOD;}}remove(k);return k;}bign operator*(const int &x) const {bign k = bign();k.len = 0;long long t[maxn];memset(t, 0, sizeof(t));for (int i = 1; i <= len; i++)t[i] = num[i] * x;for (int i = 1, g = 0; i <= len || g; i++) {k.num[++k.len] = (g + t[i]) % MOD;g = (g + t[i]) / MOD;}return k;}bign operator*(const ll &x) const {bign k = bign();k.len = 0;long long t[maxn];memset(t, 0, sizeof(t));for (int i = 1; i <= len; i++)t[i] = num[i] * x;for (int i = 1, g = 0; i <= len || g; i++) {k.num[++k.len] = (g + t[i]) % MOD;g = (g + t[i]) / MOD;}return k;}bign operator*=(const bign &x) {return *this = *this * x;}bign operator*=(const int &x) {return *this = *this * x;}bign operator*=(const ll &x) {return *this = *this * x;}bign operator/(const bign &x) const {if (x == 0)return bign();bign k = bign(), a = bign();k.flag = (flag == x.flag);k.len = len;for (int i = len; i >= 1; i--) {a = a * MOD + num[i];while (a >= abs(x)) {a -= abs(x);k.num[i]++;}}
//        if ((flag != x.flag) & a != 0)
//            k--;  //取模remove(k);return k;}bign operator/(const int &x) const {if (x == 0)return bign();bign k = bign();int a = 0;k.flag = (flag == (x >= 0));k.len = len;for (int i = len; i >= 1; i--) {a = a * MOD + num[i];k.num[i] = a / x;a %= x;}
//        if ((flag != x.flag) & a != 0)
//            k--;  //取模remove(k);return k;}bign operator/(const ll &x) const {if (x == 0)return bign();bign k = bign();int a = 0;k.flag = (flag == (x >= 0));k.len = len;for (int i = len; i >= 1; i--) {a = a * MOD + num[i];k.num[i] = a / x;a %= x;}
//        if ((flag != x.flag) & a != 0)
//            k--;  //取模remove(k);return k;}bign operator/=(const bign &x) {return *this = *this / x;}bign operator/=(const int &x) {return *this = *this / x;}bign operator/=(const ll &x) {return *this = *this / x;}bign operator%(const bign &x) const {if (x == 0)return bign();bign a = bign();for (int i = len; i >= 1; i--) {a = a * MOD + num[i];while (a >= abs(x))a -= abs(x);}
//        if (a == 0)return a;
//        if (flag && x.flag)return a;
//        if (flag && !x.flag)return a + x;
//        if (!flag && x.flag)return x - a;
//        return -a;//取模if (flag)return a;return -a;}bign operator%(const int &x) const {return *this % bign(x);}bign operator%(const ll &x) const {return *this % bign(x);}bign operator%=(const bign &x) {return *this = *this % x;}bign operator%=(const int &x) {return *this %= bign(x);}bign operator%=(const ll &x) {return *this %= bign(x);}friend bign pow(const bign &x, const bign &y) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans *= cnt;cnt *= cnt;w /= 2;}return ans;}friend bign pow(const int &x, const bign &y) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans *= cnt;cnt *= cnt;w /= 2;}return ans;}friend bign pow(const bign &x, const int &y) {bign ans = 1, cnt = x;int w = y;while (w) {if (w & 1)ans *= cnt;cnt *= cnt;w >>= 1;}return ans;}friend bign powmod(const bign &x, const bign &y, const bign &z) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w /= 2;}return ans;}friend bign powmod(const int &x, const bign &y, const bign &z) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w /= 2;}return ans;}friend bign powmod(const bign &x, const int &y, const bign &z) {bign ans = 1, cnt = x;int w = y;while (w) {if (w & 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w >>= 1;}return ans;}friend bign powmod(const bign &x, const bign &y, const int &z) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w /= 2;}return ans;}friend bign powmod(const int &x, const bign &y, const int &z) {bign ans = 1, cnt = x, w = y;while (w > 0) {if (w % 2 == 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w /= 2;}return ans;}friend bign powmod(const bign &x, const int &y, const int &z) {bign ans = 1, cnt = x;int w = y;while (w) {if (w & 1)ans = ans * cnt % z;cnt = cnt * cnt % z;w >>= 1;}return ans;}friend bign max(const bign &x, const bign &y) {return x > y ? x : y;}friend bign min(const bign &x, const bign &y) {return x < y ? x : y;}
};#define ll bign
const int N=4e5+100;
const int mod=1000;
int t,k,x;
int n;
long long ksm(int x,int p){long long tot=1,res=x;while(p){if(p&1) tot=tot*res%mod;res=res*res%mod;p>>=1;}return tot%mod;
}
int main(){scanf("%d%d",&k,&x);n=ksm(x,x);//n-=k;ll ans=1;for(int i=2;i<=n-1;i++) ans*=i;for(int i=2;i<=k-1;i++) ans/=i;for(int i=2;i<=n-k;i++) ans/=i;cout<<ans;
}
/*
WW.WBBBBB
*/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/318378.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CF39C-Moon Craters【dp】

正题 题目链接:https://www.luogu.com.cn/problem/CF39C 题目大意 坐标轴上有nnn个圆&#xff0c;给出每个圆的位置cic_ici​和半径rir_iri​。 要求选出最多的圆使得他们不相交&#xff0c;求方案。 1≤n≤20001\leq n\leq 20001≤n≤2000 解题思路 转换为选出最多的不交区…

开源库Magicodes.Storage正式发布

说明Magicodes.Storage&#xff0c;是心莱科技团队提供的统一存储库&#xff0c;相关库均使用.NET标准库&#xff08;netstandard2.0&#xff09;编写&#xff0c;支持.NET Framework以及.NET Core。我们希望&#xff0c;使用了Magicodes.Storage之后&#xff0c;开发者可以很快…

P3389 【模板】高斯消元法

P3389 【模板】高斯消元法 题目&#xff1a; 给定一个线性方程组&#xff0c;对其求解 题解&#xff1a; 还没接触高斯消元时以为是什么神仙算法&#xff0c;接触后发现。。。就是把我们手算线性方程组的方法&#xff0c;写成了代码emm。。。 比如&#xff1a; x-2y3z6 4x…

【CF 1188 A1,B,C】Add on a Tree // Count Pairs // Array Beauty

传送门 这些天风也温柔&#xff0c;题也温柔 开车啦&#xff01; 文章目录A1&#xff1a;Add on a Tree题意翻译题解证明代码实现B&#xff1a;Count Pairs题意翻译题解代码实现C&#xff1a;Array Beauty题目描述题解代码实现A1&#xff1a;Add on a Tree 题意翻译 给定一棵…

eShopOnContainers 知多少[5]:EventBus With RabbitMQ

1. 引言事件总线这个概念对你来说可能很陌生&#xff0c;但提到观察者&#xff08;发布-订阅&#xff09;模式&#xff0c;你也许就很熟悉。事件总线是对发布-订阅模式的一种实现。它是一种集中式事件处理机制&#xff0c;允许不同的组件之间进行彼此通信而又不需要相互依赖&am…

USACO Section 4

前言 好久没更新这个系列了&#xff0c;最近闲的无聊写一下。有两题搜索懒得写了。 P2737 [USACO4.1]麦香牛块Beef McNuggets https://www.luogu.com.cn/problem/P2737 解题思路 先只考虑a1a_1a1​&#xff0c;假设我们拼出了www&#xff0c;那么一定能拼出wka1wka_1wka1​…

YBTOJ:数列方案(组合数学)

文章目录题目描述解析代码题目描述 解析 如果它不取等&#xff0c;那就和方程的解这道题一样了&#xff0c;但有了等号就很头疼 如何把等号去掉呢&#xff1f; 定义BiAiiB~i~A~i~iB i A i i那么我们就可以得到&#xff1a;0<B1<B2<...<Bm<mn0<B~1~<B~2~&…

【COCI 2018/2019 Round #2】Kocka

这道题也是一个ex的模拟题 不过他比Zamjena可爱 作为一个帅气的小哥哥&#xff0c;让我们一起&#xff0c; 开启你的模拟ex大门&#xff0c;C从入门到放弃&#xff01; 题目 题目描述 我又来了&#xff01;我又来了&#xff01; 在清晨来到儿童游乐园的时候&#xff0c;出题…

Matrix Equation

题意&#xff1a; 题目给出两个矩阵X,Y,现在有两种操作 Z X Y D X⊙Y 问是否存在一个矩阵C&#xff0c;使得ACB⊙C式子成立&#xff0c;问矩阵C能有多少个 题解&#xff1a; 这个式子在模2意义下的加法就等于异或 也就相当于 那现在有 将BC移到左边 然后将Ci,j的系数进…

eShopOnContainers 知多少[6]:持久化事件日志

1. 引言事件总线解决了微服务间如何基于集成事件进行异步通信的问题。然而只有事件总线正常运行&#xff0c;微服务之间基于事件的通信才得以运转。 而现实情况是&#xff0c;总有这样或那样的问题&#xff0c;导致事件总线不稳定或不可用&#xff0c;比如&#xff1a;网络中断…

单调队列优化DP

全局最优解必然包含局部最优解&#xff0c;因此每次转移只需考虑局部最优解&#xff01;&#xff01;&#xff01; 主要内容 形如这样 的 \(\operatorname{DP}\) 转移方程&#xff1a; \[dp[i]\max_{L_i\le j\le R_i}{\{dp[i]val(i,j)\}} \]满足&#xff1a; \(\{L_i\}\) , \(\…

CF1322B-Present【双指针】

正题 题目链接:https://www.luogu.com.cn/problem/CF1322B 题目大意 给出nnn个数字aia_iai​求 ⨁i1n⨁ji1n(aiaj)\bigoplus _{i1}^n\bigoplus _{ji1}^n(a_ia_j)i1⨁n​ji1⨁n​(ai​aj​) 1≤n≤4105,1≤ai≤1071\leq n\leq 4\times 10^5,1\leq a_i\leq 10^71≤n≤4105,1≤a…

多体问题

代码&#xff1a; function SunEarthMoon % M函数文件load planets; % 将planets.mat中的变量mass、position、velocity加载过来[sun, earth, moon] deal(18, 3, 25); % sun、earth、moon分别是18、3、25行 list [sun, earth, moon]; % 1行3列矩阵 G 6.67e-11; % gr…

【CF1179 A,B,C】Valeriy and Deque / Tolik and His Uncle / Serge and Dining Room

还好题很温柔&#xff0c;温柔得我差点没做完 文章目录A&#xff1a;Valeriy and Deque题意题解代码实现B&#xff1a;Tolik and His Uncle题目题解代码实现C&#xff1a;Serge and Dining Room题目题解代码实现A&#xff1a;Valeriy and Deque 题意 给定一个双端队列&#…

YBTOJ:比赛得分(期望)

文章目录题目描述解析代码题目描述 解析 不太难的题 显然本题在AB队员大小关系相反时其对答案的贡献互为相反数。 所以想到把B队队员sort一下后就可以二分找到大小关系相反的分界点 然后维护和与平方和两个前缀数组搞一搞即可O1求出贡献 总复杂度&#xff1a;nlognnlognnlogn …

Matlab与高等数学

曲线与曲面画图 平面 对于不同曲线的表达式&#xff0c;Matlab中有不同的绘图命令&#xff0c;主要有 plot, fplot, ezplot&#xff0c;plot3&#xff0c;polar&#xff0c; 曲面 1.2 曲面画图 曲面的一般方程是F(x,y,z)0&#xff0c;一般需要将曲面的点坐标先表示出来&…

[USACO19JAN,Platinum] Redistricting

[USACO19JAN,Platinum] Redistricting 这道题A了才知道。。并不难a&#xff01; orz 题目 内存限制&#xff1a;128 MiB 时间限制&#xff1a;1000 ms 题目描述 奶牛们的最大城市Bovinopolis正在重新划分势力范围—生活在那里的主要是两个品种的奶牛&#xff08;Holsteins和…

.NET Core + JWT令牌认证 + Vue.js 通用动态权限(RBAC)管理系统框架[DncZeus]开源啦!!!...

DncZeus前言关于 DncZeusDncZeus Dnc Zeus"Dnc"--.Net Core 的缩写&#xff1b;"Zeus"--中文译为宙斯&#xff0c;是古希腊神话中的众神之王&#xff0c;奥林匹斯十二主神之首&#xff0c;统治宇宙万物的至高无上的主神&#xff08;在古希腊神话中主神专…

[gdoi2018 day1]小学生图论题【分治NTT】

正题 题目大意 一张随机的nnn个点的竞赛图&#xff0c;给出它的mmm条相互无交简单路径&#xff0c;求这张竞赛图的期望强联通分量个数。 1≤n,m≤1051\leq n,m\leq 10^51≤n,m≤105 解题思路 先考虑m0m0m0的做法&#xff0c;此时我们考虑一个强联通块的贡献&#xff0c;注意到…

背包问题 DP

各种各样的基础背包 0-1 背包 非常朴素&#xff0c;复杂度 \(O(nV)\) void z_o_pack(int c,int v) {for(int iV;i>c;i--)dp[i]max(dp[i],dp[i-c]v); } 完全背包 复杂度 \(O(nV)\) void comp_pack(int c,int v) {for(int ic;i<V;i)dp[i]max(dp[i],dp[i-c]v); } 多重背包 单…