Saving Beans HDU - 3037(卢卡斯定理) 题意: 他们想知道有多少种方法可以在n树中保存不超过m个bean(它们是相同的)。 现在他们求助于你,你应该给他们答案。 结果可能非常巨大; 你应该输出模p的结果,因为松鼠无法识别大数。 1 <= n,m <= 1000000000,p保证是一个素数 题解: 得到公式为:C(
小希的迷宫 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1272 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走。但是她设计
Tempter of the Bone 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1010 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 157407 Accepted Submission(s): 41882 Problem Description The doggie found a bon
N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 38939 Accepted Submission(s): 16549题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2553 Problem Description 在N*N的方格棋盘放置了N个皇后,使得它
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1016 Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, …, n
Color the Ball Time limit 2000 ms Memory limit 65536 kB 题目链接http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2301 (这是ZOJ的链接–数据比HDU的加强了。。) There are infinite balls in a line (numbered 1 2 3 …), and initially all of them are pain
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1114 Problem Description Before ACM can do anything, a budget must be prepared and the necessary financial support
Big Event in HDU 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1171 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. But,
Bone Collector 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2602 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20760 Accepted Submission(s): 6325 Problem Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base
Network Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1495 Accepted Submission(s): 670 Problem Description The ALPC company is now working on his own network system, which is connecting a
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 18652 Accepted Submission(s): 7268 Problem Description There are n houses in the village and some bidirectional roads connecting them. Every
题意求$(\sqrt{2} + \sqrt{3})^{2n} \pmod {1024}$$n \leqslant 10^9$Sol看到题解的第一感受:这玩意儿也能矩阵快速幂???是的,它能qwq。。。。首先我们把$2$的幂乘进去,变成了$(5 + 2\sqrt{6})^n$设$f(n) = A_n + \sqrt{6} B_n$那么$f(n+1) = (A_n + \sqrt{6} B_n ) * (5 + 2\sqrt{6})$乘
题目:Problem - 1050 (hdu.edu.cn) #include<bits/stdc++.h> using namespace std; int main(){ int a,b,c[200],d,e,temp; cin>>a; for(int i=0;i<a;i++){ cin>>b; for(int i=0;i<200;i++){ c[i]=0; } for(int i=0;i<b;i++){ cin&
回文子串 回文分为奇数回文和偶数回文,即字符串的长度为奇数还是偶数。其实只需要讨论奇数的情况,即以某个字符为中心,左右两边的字符按照中心对称的情况(偶数的情况可以通过本文末尾的方法转换成奇数的情况)。 最长回文子串 朴素算法
原题链接 考察:欧拉定理 思路: 已知每个8888...888都可以被表示成: \[nums = \frac {8\times(10^x-1)}{9} \]\[nums \equiv 0 \pmod L \]\[(10^x-1)\% \frac{9\times L}{gcd(8,L)}==0 \] 根据欧拉定理,若10与\(\frac{9\times L}{gcd(8,L)}\)互质,则存在最小的正整数x,使得等式
题目 求最短路,最小值最好用bfs。 这道题目的代码,本菜鸡写的比较傻。 #include <cstdio> #include <map> #include <queue> #include <cstring> #include <algorithm> using namespace std; const int maxn=202; char maze[maxn][maxn]; int n, m, ans=1000; int d1[maxn][m
传送门 题意:给定n颗导弹(n默认为小于等于1e3吧),一套导弹拦截系统最开始能拦截任意高度的导弹,但是后面每次拦截的导弹的高度不能超过前一次拦截的导弹,现在有导弹依次袭来,给定每颗导弹的高度,问最少需要多少套导弹拦截系统。 题解:求最长上升子序列,但是一直不知道为什莫是这样, 最佳解
原题链接 考察:数位dp 这道题能用递推的方式实现吗...如果有请告知本蒟蒻(.) 错误思路: 建立dp数组f[pos][len][last]表示枚举到第pos位,目前长度为len,上一位是last的情况.如果我们枚举的i>last,len+1.如果i<=last,len不变,last不变. WA数据:12534 这样计算它的最长上升
原题链接 考察:数位dp 思路: 应该是入门题,但我WA了两次....这道题直接求连续的49反而不大好求,我们反过来求不连续49的个数,然后再减去即可. Code #include <iostream> #include <cstring> #include <vector> using namespace std; typedef long long LL; const int N = 20;
原题链接 考察:数位dp 思路: 预处理时,不计入每位数字为4或首位为6,次位为2的数字. 但是注意计算左分支的时候,我们是ans+=f[i+1][枚举的数字],如果枚举的数字为2,实际还需特判上一位.因为预处理首位数字为2时没有考虑上一位是什么. Code #include <iostream> #include <c
题目链接 题目大意 求n个数的子序列的最大异或和。 解题思路 求出n个数的线性基并排序,然后将k二进制异或上线性基中对应的代表元素即可。 代码 const int maxn = 2e5+10; ll arr[maxn]; vector<ll> b; //b中存的每个二进制位的代表元素 void insert(ll x) { //设x在线性基
原题链接 考察:博弈论 思路: 威佐夫博弈,求先手必胜的第一步. 要先手必胜,即把后手面临的局面改为先手必败.当n==(m-n)*k即先手必败.这里分两种情况: (m-n)*kd,d<n时,我们可以从n堆里取,但我们需要保证新局面下m,与n的差值不变,才能保证差值*kn 从m堆里取,此时m堆的值不
原题链接 考察:线段树 思路: 和校门外的树(增强版)那道题差不多,我们不用管哪些瓶子有花,哪些没有.只要add,范围内从小到大 = 1.只要删除,sum[l,r] = 0. Code #include <iostream> #include <cstring> using namespace std; const int N = 50011,INF = 0x3f3f3f3f; struct No
ACMer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6539 Accepted Submission(s): 3086 Problem Description There are at least P% and at most Q% students of HDU are ACMers, now I want to know how many