Aria's Loops
https://www.hackerrank.com/contests/101hack41/challenges/arias-loops
可以看我以前的笔记,http://www.cnblogs.com/liuweimingcprogram/p/6091396.html
或者我在discusses的题解
I have my thought in this problem The first thing in the editorial is this problem problem:
count how many hello world
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
for (int k = j + 1; k <= n; ++k)
cout << "hello world" << endl;
observe i < j < k <= n. so this ans is from 1....n select 3 different number,build a triple.The ans will be C(n, 3)
think more deeply, let define xi be the distance between xi and x(i - 1) so x1 >= 1 because the number start from one.and then x2 >= 1 && x3 >= 1 because they can not be the same. so the ans is the ans of how many solution of x1 + x2 + x3 <= n this is a very classics problem.Go to the internet searching.
and now this problem can be solve using the second method x1 >= 1 && x2 >= 1 && x3 >= 2 && x4 >= 3 ...... so the ans is C(n - 1 - (k * k - 3 * k) / 2, k); may be my English is very poor so thay you can not understand. I feel so sorry
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
#define MY "H:/CodeBlocks/project/CompareTwoFile/DataMy.txt", "w", stdout
#define ANS "H:/CodeBlocks/project/CompareTwoFile/DataAns.txt", "w", stdout #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
LL n, k;
const int MOD = 1e9 + ;
LL quick_pow (LL a,LL b,LL MOD) {
//求解 a^b%MOD的值
LL base=a%MOD;
LL ans=; //相乘,所以这里是1
while (b) {
if (b&) {
ans=(ans*base)%MOD; //如果这里是很大的数据,就要用quick_mul
}
base=(base*base)%MOD; //notice
//注意这里,每次的base是自己base倍
b>>=;
}
return ans;
} LL C (LL n,LL m,LL MOD) {
if (n<m) return ; //防止sb地在循环,在lucas的时候
if (n==m) return ;
LL ans1 = ;
LL ans2 = ;
LL mx=max(n-m,m); //这个也是必要的。能约就约最大的那个
LL mi=n-mx;
for (int i = ; i <= mi; ++i) {
ans1 = ans1*(mx+i)%MOD;
ans2 = ans2*i%MOD;
}
return (ans1*quick_pow(ans2,MOD-,MOD)%MOD); //这里放到最后进行,不然会很慢
}
LL Lucas (LL n,LL m,LL MOD) {
LL ans=;
while (n && m && ans) {
ans=ans*C(n%MOD,m%MOD,MOD)%MOD;
n /= MOD;
m /= MOD;
}
return ans;
} void work() {
cin >> n >> k;
LL N = n - - ((k * k - * k) / );
if (N < ) cout << << endl;
else cout << Lucas(N, k, MOD) << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
work();
return ;
}
我知道这里不用lucas,但是自己的模板,一复制就是这样,而且这样用lucas复杂度不会增加。
Aria's Loops的更多相关文章
- Nested Loops join时显示no join predicate原因分析以及解决办法
本文出处:http://www.cnblogs.com/wy123/p/6238844.html 最近遇到一个存储过程在某些特殊的情况下,效率极其低效, 至于底下到什么程度我现在都没有一个确切的数据, ...
- SQL Tuning 基础概述06 - 表的关联方式:Nested Loops Join,Merge Sort Join & Hash Join
nested loops join(嵌套循环) 驱动表返回几条结果集,被驱动表访问多少次,有驱动顺序,无须排序,无任何限制. 驱动表限制条件有索引,被驱动表连接条件有索引. hints:use_n ...
- track message forwards, avoiding request loops, and identifying the protocol capabilities of all senders along the request/response chain
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html The TRACE method is used to invoke a remote, ...
- Sort merge join、Nested loops、Hash join(三种连接类型)
目前为止,典型的连接类型有3种: Sort merge join(SMJ排序-合并连接):首先生产driving table需要的数据,然后对这些数据按照连接操作关联列进行排序:然后生产probed ...
- HDOJ 3853 LOOPS
水概率DP.... LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others ...
- IOS- Run Loops
Run Loops Run loops是线程相关的的基础框架的一部分.一个run loop就是一个事件处理的循环,用来不停的调度工作以及处理输入事件.使用run loop的目的是让你的线程在有工作的时 ...
- 译文 对无障碍网页应用(ARIA)的选择
//本文编辑格式为Markdown,译文同时发布在众成翻译 对无障碍网页应用(ARIA)的选择 让网站对每个人都能访问是一件相当艰难的工作,尤其是在我们使用自定义标记解决方案(custom marku ...
- HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Problem Description Akemi Homura is a M ...
- LOOPS(HDU 3853)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
随机推荐
- mybatis xml文件解析
1 parameterType 如果参数只有一个,比如一个id,即int类型的id,那么parameterType直接是int. 如果参数有多个,那么就用表中一行对应的类,默认是类的名字和表中列的名字 ...
- var let Hositing const Temporal Dead Zone
var let Hositing const Temporal Dead Zone 临时死区
- Lambda 闭包 匿名 函数 类
深入理解Java 8 Lambda(语言篇——lambda,方法引用,目标类型和默认方法) - _Luc_ - 博客园 https://www.cnblogs.com/figure9/p/java-8 ...
- 浏览器上的Qt Quick
你想不想在浏览器上运行你的Qt Quick程序呢?在Qt 5.12之前,唯一的方法是使用Qt WebGL Streaming技术把界面镜像到浏览器上.但该方法有不少缺陷,下文会说.前不久随着Qt 5. ...
- eclipse输入提示 设置
- amazon lightsail
https://51.ruyo.net/6038.html https://aws.amazon.com/cn/lightsail/
- MYSQL进阶学习笔记九:MySQL事务的应用!(视频序号:进阶_21-22)
知识点十:MySQL 事务的应用 (21-22) 为什么要引入事务: 为什么要引入事务这个技术呢?现在的很多软件都是多用户,多程序,多线程的.对同一表可能同时有很多人在用,为保持数据的一致性,所以提出 ...
- 为什么越来越多公链项目将WASM拥入怀中?
最近越来越多的项目开始转向VNT使用的WASM,像EOS.Ontology,包括最初引入虚拟机EVM运行智能合约环境的以太坊,最近也开始转向使用WASM. 什么是WASM? WASM ,全称:WebA ...
- 更改ssh远程登录端口.sh
#!/bin/bash #liu_dong sed -i "s/\#Port 22/Port 31961/g" /etc/ssh/sshd_config sed -i " ...
- centos7用lvm扩展xfs文件系统的根分区
centos7中默认使用的是xfs文件系统,此文件系统的特点,可以另外查找资料,这里说一下对文件系统的扩容: 1.先看一下没扩容之前的分区大小 2.添加一块新磁盘,并进行分区.格式化(格式化的时候用m ...