https://nanti.jisuanke.com/t/31721 题意 有肉,鱼,巧克力三种食物,有几种禁忌,对于连续的三个食物:1.这三个食物不能都相同:2.若三种食物都有的情况,巧克力不能在中间:3.如果两边是巧克力,中间不能是肉或鱼.求方案数. 分析 将meat ,  chocolate,fish 用 0 ,1 , 2 表示. 对于 n 来说,我们只关注后两位,因为 若 n - 1 的所有方案解决的话,我们在 n - 1 的方案添加0, 1,2 就行,然后根据禁忌 去除不可能的方案.…
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 3 c…
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 33 …
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous. Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 3 c…
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N), and each time a child is invited, Miss Li…
这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she will ask the mirror: 'Mirror mirror tell me, who is the most beautiful girl in the world?' If the mirror says her name, she will praise the mirror: '…
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know which one to choose, so they use a way to make decisions. They have several boxes of candies, and there are ii candies in the i^{th}ith box, each cand…
There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry the weight of V[i]V[i] and the number of the i^{th}ith kind of ship is 2^{C[i]} - 12C[i]−1. How many different schemes there are if you want to use thes…
Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of CC, so we represent it as AA * BB * CC. One day, he finds that his room is filled with unknown dark energy. Bob wants to neutralize all the dark ener…
Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring wonderful substring when the times it appears in that string is between AA and BB (A \le times \le BA≤times≤B). Can you calculate the number of wonderful…
There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invited,…
A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics when he was young, and was entangled in some mathematical curses. He studied hard until he reached adulthood and decided to use his knowledge to esca…
ACM-ICPC 2018 焦作赛区网络预赛 Give Candies n个糖果分给n个小朋友 从1到n个小朋友依次给,每次随机给个数,至少一个,知道没有糖果为止. 问糖果的分布情况方案数. 输出方案数mod 109+710^9+7109+7 考虑只有前i个小朋友得到糖的情况,于是等价于将n个糖果分为i堆,插板法易得方案数是(n−1i−1)\binom{n-1}{i-1}(i−1n−1​) 总方案数∑i=1n(n−1i−1)=2n−1\sum_{i=1}^{n}\binom{n-1}{i-1}=…
262144K   There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance c_ici​. Haze is a Magical Girl that lives in City 11, she can choose no more than KK roads and make their distanc…
https://nanti.jisuanke.com/t/31721 题意 n个位置 有几个限制相邻的三个怎么怎么样,直接从3开始 矩阵快速幂进行递推就可以了 #include <bits/stdc++.h> using namespace std; typedef long long ll; ,maxn=; struct Matrix { ll m[maxn][maxn]; Matrix() { memset(m,,sizeof(m)); } void init() { ; i<max…
A. Magic Mirror 水. #include <bits/stdc++.h> using namespace std; int t; ]; inline bool work() { int len = strlen(s); ) return false; ] != ] != 'J') return false; ] != ] != 'E') return false; ] != ] != 'S') return false; ] != ] != 'S') return false;…
https://nanti.jisuanke.com/t/31719 题意 让你分别判断n或(n-1)*n/2是否是完全平方数 分析 二分高精度开根裸题呀.经典题:bzoj1213 用java套个板子求出平方根,再乘回来检验一下就好. import java.util.*; import java.math.*; public class Main{ static BigInteger check(BigInteger n,BigInteger x) { BigInteger ans=BigIn…
题目链接:https://nanti.jisuanke.com/t/31714 题意:给你一棵树,初始全为0,有四种操作: 1.u-v乘x    2.u-v加x   3. u-v取反  4.询问u-v的和 思路: 除去第三个操作就是很简单的树链剖分+线段树多重标记下放,所以我们只要考虑怎么维护第三个操作就好了, 由题目给的取反可知:!x =  (2^64-1) - x;   但是这样维护还是很麻烦,因为这道题是对2^64取模的,我们可以 尝试把这个式子转换成只有加法和乘法的,这样就可以将其和前面…
树链剖分若不会的话可自行学习一下. 前两种操作是线性变换,模\(2^{64}\)可将线段树全部用unsigned long long 保存,另其自然溢出. 而取反操作比较不能直接处理,因为其模\(2^{64}\)的特殊性,可将其转化为线性变换. 显然 \[-x\equiv (2^{64}-1)*x (mod\ 2^{64})\] 因为\[!x = (2^{64}-1) -x \] 所以 \[ !x = (2^{64}-1) + (2^{64}-1)x\] #include<bits/stdc++…
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know which one to choose, so they use a way to make decisions. They have several boxes of candies, and there are ii candies in the i^{th}i th box, each can…
题目链接:https://nanti.jisuanke.com/t/31001 题目大意:给出一个含有n个点m条边的带权有向图,求1号顶点到n号顶点的最短路,可以使<=k条任意边的权值变为0. 样例输入 复制 1 5 6 1 1 2 2 1 3 4 2 4 3 3 4 1 3 5 6 4 5 2 样例输出 复制 3 解题思路:可以用两种做法,不过都差不多,应该算是同一种思路的不同写法.第一种是在建图时,将一个点拆成k个层次的点,应该总共有k+1层,每个相同层次的点按输入的边权连接,每个点可以向它…
题目链接:https://nanti.jisuanke.com/t/31716 题目大意:有n个孩子和n个糖果,现在让n个孩子排成一列,一个一个发糖果,每个孩子随机挑选x个糖果给他,x>=1,直到无糖果剩余为止.给出数字n,问有多少种分发糖果的方法. 样例输入 复制 1 4 样例输出 复制 8 解题思路:我们可以这样想,一个糖果的话,应该是只有1种方法记为x1,如果是两个糖果的话,有两种方法即为x2,分别为(1,1)和(2),从中我们可以想到如果n个糖果的话,就可以分为第n个人取1个的话就有x(…
https://nanti.jisuanke.com/t/31720 题意 t组样例,n种船只,q个询问,接下来n行给你每种船只的信息:v[i]表示这个船只的载重,c[i]表示这种船只有2^(c[i]−1)只. 对于每个询问,求用这些船装s的货物的方案数有多少,用到的船必须装满. 分析 一眼就是背包类的题,多重背包求方案数,将数量为m的物体分为log2(m)种物体,然后做01背包.在这里只需改改多重背包模板的转移式子就好. 背包九讲小总结:https://www.cnblogs.com/fht-…
https://nanti.jisuanke.com/t/31718 题意 问能否用1*1*2的长方体填满a*b*c的长方体. 分析 签到.如果a.b.c都是奇数,一定不能. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; int main(){ int a,b,c; while(~scanf("%d%d%d",&a,&b,&c)){ )&&…
https://nanti.jisuanke.com/t/31716 题意 n颗糖果n个人,按顺序给每个人任意数目(至少一个)糖果,问分配方案有多少. 分析 插板法或者暴力打表后发现答案就为2^(n-1),只是这个n有点大.于是马上用java.然而现实相当残酷,超时. 然后想到降幂,即(a^b)%m=a^(b%phi(m))%m,当gcd(b,m)==1.这里显然互质,于是降幂后仍然用java写,还是tle. 而后还尝试了C++大数来写,可能是使用姿势错误,也t了. 到了最后一小时,没错,我们队…
https://nanti.jisuanke.com/t/31711 题意 m个符号必须按顺序全用,n个房间需顺序选择,有个初始值,问最后得到的值最大是多少. 分析 如果要求出最大解,维护最大值是不能得到的,因为有负数的参与,所以我们维护最大值和最小值.不管那么多,反正答案肯定是由极值产生的. 定义dp1[i][j]为用了i个符号,走了j间房后的最大值.因而dp2[][]就是对应的最小值.然后按要求转移. #include<bits/stdc++.h> using namespace std;…
https://nanti.jisuanke.com/t/31710 题意 若输入的是Jessie或jessie,输出Good guy!,否则输出Dare you say that again? 分析 水题,学习一下string直接转小写的操作,方便. #include<bits/stdc++.h> using namespace std; typedef long long ll; ; int main(){ int t; cin>>t; string s; while(t--)…
There are NNN children in kindergarten. Miss Li bought them NNN candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N)(1...N), and each time a child is…
Bob is a sorcerer. He lives in a cuboid room which has a length of AAA, a width of BBB and a height of CCC, so we represent it as AAA * BBB * CCC. One day, he finds that his room is filled with unknown dark energy. Bob wants to neutralize all the dar…
<题目链接> 题目大意: 有N个城市,这些城市之间有M条有向边,每条边有权值,能够选择K条边 边权置为0,求1到N的最短距离. 解题分析: 分层图最短路模板题,将该图看成 K+1 层图,然后具体解析见代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <queue> using namespace std;…