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 ...
随机推荐
- A toolbox to build your own build server
A toolbox to build your own build server LambdaCD - Build Pipelines as Code https://www.lambda.cd/ A ...
- $.post 使用案例
$.post( aplnCommon.topUrl + 'ajaxLogin/ajaxLogin.action', { 'userLoginId' : userName, 'pwd' : userPw ...
- HDU1300 Pearls —— 斜率优化DP
题目链接:https://vjudge.net/problem/HDU-1300 Pearls Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- springboot在eclipse实现热部署
eclipse使用spring-tool-suite插件创建springboot项目,项目创建完成后. 选中项目,右键 Spring Tools --> Add Boot Devtools 点 ...
- silverlight DataGrid 内嵌ComboBox 实现加载和保存
<Grid x:Name="LayoutRoot" Background="White" Height="322" Width=&qu ...
- 非常精彩的Silverlight 2控件样式
概述 大家是否觉的现在Silverlight 2提供的默认的控件不能满足自己的要求?好在Silverlight的控件可以运用皮肤,微软Silverlight控件的设计者的主管Corrina开发了几套非 ...
- I.MX6 不一定要设置BOOT_MODE进入烧录模式
/************************************************************************* * I.MX6 不一定要设置BOOT_MODE进入 ...
- NOI1995 石子合并
传送门 这道题是经典的区间DP.因为它要求有每两个相邻的石子堆合并,所以很显然对于区间[l,r]内的情况,我们只要枚举端点k,之后把这左右两端的石子合并取最大/小即可. 之后,这题是环形怎么破?显然不 ...
- linux/unix下 pid文件作用浅析
l在linux系统的目录/var/run下面一般我们都会看到很多的*.pid文件.而且往往新安装的程序在运行后也会在/var/run目录下面产生自己的pid文件.那么这些pid文件有什么作用呢?它的内 ...
- Bug: CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: 0.0000 to 0.0000
原因是当前的scheduleOnce还没有执行完成, 可以将scheduleOnce方法改写成另外一种形式,把CCDelayTime和CCCallFunc拼接构造延迟事件调用: CCDelayTime ...