世上只有一种英雄主义,就是在认清生活真相之后依然热爱生活。

题目描述

finally, you got into the cellar of your preferred brewery where you expected many large piles of beer barrels to be stored. You are eager to inspect the barrels and maybe even their content (a lot and lot of content, actually...). Unfortunately, you find only five barrels, all hopelessly empty and dry. Some numbers are painted on the first four barrels, one number on each of them. A note is attached to the fifth barrel. Behind the barrels in the dark, there is some low and barely discernible door in the wall, leading quite obviously to another lower cellar where you hope a whole slew of full barrels is kept hidden. The door is locked with a heavy and complex looking lock. With no obvious further constructive action in mind, you sit down to study the note on the fifth barrel.
Its essence is the following.
Denote the numbers painted on the first, second, third and fourth barrel by A, B, K and C.
Numbers A, B and C are just single digits.
Now imagine that in the distant future some incredibly powerful computer (powered by quantum yeast) prints a list of all numbers which have exactly K digits and in which each digit is equal to A or B. Another equally mighty computer then takes the list and also the value C as the input and calculates the number of occurrences of digit C in the whole list.
The resulting number taken modulo 1 000 000 007 is to be typed into the door lock to open it and to gain access to the lower cellar.
You decide to calculate that number in your notebook you took with you.

输入

The input consists of a single line with four integers A, B, K, C (1 ≤ A, B, C ≤ 9, 0 ≤ K ≤ 1000)which represent the numbers painted on the first four barrels.

输出

Output a single integer which opens the door lock.

样例输入 Copy

1 2 3 2

样例输出 Copy

12
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const ll mod=1000000007;
int A,B,C,K;
ll ls,jg;
ll ksm(int a,ll b,ll mod)
{ll ans=1;while(b){if(b&1)ans=(ans%mod*a%mod)%mod;a=(a%mod*a%mod)%mod;b>>=1;}return ans;
}
ll plzh(int n,int m)
{ll ans=1;int ls=m;while(ls){ans=(ans%mod*n%mod)%mod;n--;ls--;}return ans;
}
int main()
{cin>>A>>B>>K>>C;if(C!=A&&C!=B)cout<<0<<endl;else if(A==B)cout<<K<<endl;else{for(int i=1; i<=K; i++){ls=(i%mod*plzh(K,i)%mod*ksm(plzh(i,i),mod-2,mod)%mod)%mod;jg=(jg%mod+ls)%mod;}cout<<jg<<endl;}return 0;
}

题意:一个K位数,只能包含A或B,找出所有满足条件的K位数,然后统计这些K位数中总共包含多少个C。

分析:本题显然(别打我)计算的解中A,B并不参与运算,无非就是用他们来判断C个数的结果。

首先C与A,B都不想相等时,个数无论怎么排都是0

其次,A与B相等时,就只有一种排法,即全为A(或B),K是几位数就有多少个。

然后就是排列组合了,总共这K位数就包含两个数字,可得公式算出这样的K位数有多少个:C(K,1)+C(K,2)+C(K,3)+...+C(K,K)

个数就是每个对应的组合数乘以个数即可(可能说的不清楚,我也不知道怎么说):C(K,1)*1+C(K,2)*2+C(K,3)*3+...+C(K,K)*K

其中求C(n,m)转换为:C(n,m)=A(n,m)/A(m,m);注意这里有除法了,题目中要mod一个数,别忘了逆元

问题 A: Beer Barrels相关推荐

  1. CTU Open Contest 2019 计蒜客重现补题报告

    个人总结 寒假过完的第一场比赛,总是有很多问题.主要有以下两点:一是寒假做题有点依赖翻译,看不下去很长的英文题面,导致这次比赛的一些题目看很长时间也没看懂.二是发现了自己的做题量仍然很少,很多题目缺乏 ...

  2. BBL 啤酒桶体积代表什么?

    啤酒桶是美国惯用的啤酒体积单位.啤酒桶可简写为bbl:例如,1 个啤酒桶可以写成 1 bbl. BBL 是啤酒桶(Beer barrel)的缩写,它是美国啤酒厂啤酒体积的官方计量单位.它可以写成一桶啤 ...

  3. CTU Open Contest 2019

    A. Beer Barrels 题意:给出四个整数:A,B,K,C,A,B,C 都是大于 0 的个位数,问在所有仅由 A 或 B 组成的 K 位数中(K 位数的每一位都是 A 或 B),数字 C 的个 ...

  4. CodeForces-985C Liebig's Barrels

    CodeForces-985C Liebig's Barrels Description You have m = n·k wooden staves. The i-th stave has leng ...

  5. C. Liebig's Barrels

    You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble nbarrels consisti ...

  6. 利用轻量级js插件Beer Slider实现新老图片的实时对比

    因业务需求,需要在H5中实现场景20年的变化对比,最终找到了一款轻量级的js图片对比插件Beer Slider.它的基本目的是比较图像的两个版本,例如在两个不同时刻拍摄的相同对象,预编辑的照片及其处理 ...

  7. 20180710-B · Craft Beer USA · ggplot2 geom_density_ridges_gradient 核密度估计峰峦图 字体设置 · R 语言数据可视化 案例 源码

    所有作品合集传送门: Tidy Tuesday 2018 年合集传送门: 2018 Craft Beer USA 欢迎来到ggplot2的世界! ggplot2是一个用来绘制统计图形的 R 软件包.它 ...

  8. Is your mobile free as in free beer or free as in free speech?

    Free 这个字可以翻作自由,也可以翻作免费,因此玩自由软体的英语系人士常常在使用这个字的时候,会说 "free" as in "free speech" (言 ...

  9. 20180710-A · Craft Beer USA · ggplot2 geom_col 条形图 facet_geo theme 字体设置 画图 图例 · R 语言数据可视化 案例 源码

    所有作品合集传送门: Tidy Tuesday 2018 年合集传送门: 2018 Craft Beer USA 欢迎来到ggplot2的世界! ggplot2是一个用来绘制统计图形的 R 软件包.它 ...

  10. cf Educational Codeforces Round 44 C. Liebig's Barrels

    原题: C. Liebig's Barrels time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

最新文章

  1. 怎样更好地团队协作沟通?
  2. 【LeetCode从零单排】No133. clon graph (BFS广度优先搜索)
  3. Oracle-Oracle SQL Report (awrsqrpt.sql/awrsqrpi.sql)生成指定SQL的统计报表
  4. Git利用命令行提交代码完整步骤
  5. 关于c++ pair自己遇到的一个问题?为何不一样?为何第一个程序不能返回pair内数组的值呢?(已经解决)
  6. Node中使用token(基于第三方包jsonwebtoken)
  7. 图文讲解:iOS App提交流程
  8. Atitit 消息系统 mq 的艺术 attilax总结 v5 t88.docx Atitit 消息系统 mq 之道 attilax总结 1. 概念 broker topic producer
  9. 充电器兼容qi是什么意思_什么是“经Qi认证”的无线充电器?
  10. 读文万卷025期:使用MRI形态学特征和表观弥散系数预测WHO II/III级胶质瘤分子状态;帕金森病的中脑的定量磁敏感成像
  11. 朴素贝叶斯与贝叶斯信念网络
  12. Logstash:使用 dissect 导入 CSV 格式文档
  13. Java 直接插入 CLOB/BLOB 数据到 Oracle 数据库
  14. 查看获取别人的微信公众号二维码
  15. ol3中妙用Arcgis Server Rest Export接口模拟WMS,并实现属性过滤
  16. 音频信号输入itc服务器,ITC公共广播系统
  17. 国家卫生计生委医院管理研究所简介
  18. 查尔斯·巴贝奇——计算机先驱者之父
  19. vi下Makefile的自动生成
  20. 拆t420s屏轴_手工改造 ThinkPad T420s升级FHD IPS屏

热门文章

  1. iOS企业ipa(299)证书制作、打包发布全流程
  2. python Calendar日历模块函数介绍
  3. 新浪公司总裁兼首席执行官 曹国伟
  4. 华住集团股权曝光:季琦持股30.5% 雅高不再是股东
  5. 页面加载性能之如何测试打开速度
  6. 动手学深度学习v2 课程笔记 — 深度学习基础
  7. 32位计算机支持word系统,Office 32位与64位版本有什么区别?
  8. C语言:房贷计算器(等额本息与等额本金对比计算器)
  9. python中‘ ‘.join()的使用
  10. Windows Server 2019 配置DHCP