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 ...
随机推荐
- XJTUOJ wmq的A×B Problem FFT/NTT
wmq的A×B Problem 发布时间: 2017年4月9日 17:06 最后更新: 2017年4月9日 17:07 时间限制: 3000ms 内存限制: 512M 描述 这是一个非常简 ...
- 注意css 小细节 颜色能缩写尽量缩写
如 background: #333333; 改为 background: #333;
- ADB结构及代码分析【转】
本文转载自:http://blog.csdn.net/happylifer/article/details/7682563 最近因为需要,看了下adb的源代码,感觉这个作者很牛,设计的很好,于是稍微做 ...
- POJ1087 A Plug for UNIX —— 最大流
题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K T ...
- 格式化磁盘,提示 is apparently in use by the system
一般是被mdadm占用着. 使用 cat /proc/mdstat 查看所有 找到欲格式化盘符号. 使用 mdadm --stop /dev/md0 mdadm --remove /dev/md0 ...
- 深入理解WeakHashmap
转自:http://mikewang.blog.51cto.com/3826268/880775 (一) 查看API文档,WeakHashmap要点如下: 1. 以弱键 实现的基于哈希表的 Map.在 ...
- 「LuoguP4753」濑 River Jumping(贪心
Description 有一条宽度为 N 的河上,小D位于坐标为 0 的河岸上,他想到达坐标为 N 的河岸上后再回到坐标为 0 的位置.在到达坐标为 N 的河岸之前小D只能向坐标更大的位置跳跃,在到达 ...
- CoreGpaphics
CoreGpaphics基本应用 CGAffineTransformMake开头的函数 是基于最初始的位置来变化的 带有CGAffineTransform参数是基于CGAffineTransform的 ...
- 在msys里进行复制和粘贴操作
You can copy text from an MSYS window to the clipboard simply by selecting the text you want to copy ...
- #define WM_COMM_BREAK_DETECTED WM_USER+1
一.#define WM_COMM_BREAK_DETECTED WM_USER+1定义一个用户自定义消息WM_COMM_BREAK_DETECTED,它是自定义消息,非系统消息 为了防止用户定义的消 ...