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,一经查实,立即删除!

相关文章

开源库Magicodes.Storage正式发布

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

【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…

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;网络中断…

多体问题

代码&#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;在古希腊神话中主神专…

P5081 Tweetuzki爱取球(期望)(线性求逆元)

文章目录题目描述解析代码题目描述 解析 首先有一个很重要的引理&#xff1a; 若一件事做成的概率是p&#xff0c;则其做成需要次数的期望是1/p 为什么呢&#xff1f; 我们设做成这件事的期望次数是x 就可以列出方程&#xff1a; x1p∗0(1−p)∗xx1p*0(1-p)*xx1p∗0(1−p)∗x …

【 CF1186D,E,F】Vus the Cossack and Numbers/Vus the Cossack and a Field/Vus the Cossack and a Graph

太ex了&#xff0c;哭了哭了orz 后面两道平均一道花了我一天啊&#xff01; 文章目录D&#xff1a;Vus the Cossack and Numbers题意翻译题解代码实现E&#xff1a;Vus the Cossack and a Field题意翻译题解代码实现F:Vus the Cossack and a Graph题目暴力题解代码实现官方题解…

IdentityServer4与ocelot实现认证与客户端统一入口

关于IdentityServer4与ocelot博客园里已经有很多介绍我这里就不再重复了。ocelot与IdentityServer4组合认证博客园里也有很多&#xff0c;但大多使用ocelot内置的认证&#xff0c;而且大多都是用来认证API的&#xff0c;查找了很多资料也没看到如何认证oidc&#xff0c;所以这里…

YBTOJ:彩球抽取(期望)

文章目录题目描述解析代码题目描述 解析 首先&#xff0c;可以使用dp解决本题 设fi,j,k&#xff1a;操作i轮之后编号j的小球有k个的概率 转移和统计答案就都不难了 但是还有一个问题 不难发现这个题循环下去是可以无穷无尽的 所以限定一个i的上界&#xff08;如500000&#xf…

魔改森林

题意&#xff1a; 曾经有一道叫做迷雾森林的题目&#xff0c;然而牛牛认为地图中的障碍太多&#xff0c;实在是太难了&#xff0c;所以删去了很多点&#xff0c;出了这道题。 牛牛给出了一个n行m列的网格图 初始牛牛处在最左下角的格点上(n1,1)&#xff0c;终点在右上角的格点…

基于IdentityServer4 实现.NET Core的认证授权

IdentityServer4是什么&#xff1f;IdentityServer4是基于ASP.NET Core实现的认证和授权框架&#xff0c;是对OpenID Connect和OAuth 2.0协议的实现。OpenID Connect 和 OAuth2.0是什么OpenID Connect:OpenID Connect由OpenID基金会于2014年发布的一个开放标准, 是建立在OAuth …

[COCI 2018#5]Parametriziran

这道题呢&#xff01; 算了&#xff0c;不要让这玩意儿活着祸害众生吧&#xff01;让我们来拯救苍生于苦海之中&#xff01;&#xff01; 骚话连篇ing 题目 由小写英文字母和问号组成的字符串成为参数化单词&#xff08;例如&#xff1a;??cd,bcd,??&#xff09;。如果两…