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 ...
随机推荐
- 【bzoj3671】[Noi2014]随机数生成器
优先按照它说明的方法处理数组 然后为了让数列中尽可能多的出现小的数字 所以1是必须要出现的,这样才能使整个数列的排序后字典序最小. 我们思考,如果2也能在这个数列中那就最好不过了 但是2有可能不在这个 ...
- android 图片内存问题
在android开发过程中,经常遇到oom的问题,原因有很多种,其中最难处理的是图片造成的oom,于是在网络上对比了几个图片加载的库,最终选择了Facebook的fresco库(github地址:ht ...
- springboot如何使用外部tomcat容器
一般情况spring-boot-starter-web是自带tomcat(即springboot内嵌tomcat),所以打包直接生成jar包,用java -jar命令就可以启动. 但,有时我们希望用w ...
- 如何查看一个Application是32位的还是64位的?
使用process explorer查看,找到对应的进程. 注册表的路径是Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ 使用powershell查 ...
- YTU 2481: 01字串
2481: 01字串 时间限制: 1 Sec 内存限制: 128 MB 提交: 103 解决: 72 题目描述 对于长度为7位的一个01串,每一位都可能是0或1,一共有128种可能.它们的前几个是 ...
- LoadRunner检查点使用小结
LR中检查点有两种:图片和文字. 常用检查点函数如下: 1)web_find()函数用于从 HTML 页中搜索指定的文本字符串: 2)web_reg_find()函数注册一个请求,以在下一个操作函数( ...
- poj 1469 COURSES 解题报告
题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...
- driver, module以及怎么看他们
1. driver和module的区别 https://unix.stackexchange.com/questions/47208/what-is-the-difference-between-ke ...
- receive和process的过程
(一) receive最终在fuse_kern_chan.c中的fuse_kern_chan_receive函数实现,使用系统调用读取 res = read(fuse_chan_fd(ch), buf ...
- [BZOJ 3697] 采药人的路径
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3697 [算法] 首先 , 将黑色的边变成1 ,白色的边变成-1 那么 , 问题就转化 ...