[Usaco2011 Feb]Generic Cow Protests】的更多相关文章

2274: [Usaco2011 Feb]Generic Cow Protests Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 196  Solved: 122[Submit][Status] Description Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another…
Description Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer A_i (-10,000 <= A_i <= 10,000). FJ…
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows are conducting another one of their strangeprotests, so each cow i is holding up a sign with an integer A_i(-10,000 <= A_i <= 10,000). FJ knows the…
[题解] 很容易可以写出朴素DP方程f[i]=sigma f[j] (sum[i]>=sum[j],1<=j<=i).  于是我们用权值树状数组优化即可. #include<cstdio> #include<algorithm> #define N 200010 #define rg register #define LL long long #define Mod (1e9+9) using namespace std; int n,n2; LL t[N],f[…
USACO 奶牛抗议 Generic Cow Protests Description 约翰家的N头奶牛聚集在一起,排成一列,正在进行一项抗议活动.第i头奶牛的理智度 为Ai,Ai可能是负数.约翰希望奶牛在抗议时保持理性,为此,他打算将所有的奶牛隔离成 若干个小组,每个小组内的奶牛的理智度总和都要大于零.由于奶牛是按直线排列的,所以 一个小组内的奶牛位置必须是连续的. 请帮助约翰计算一下,存在多少种不同的分组的方案.由于答案可能很大,只要输出答 案除以1,000,000,009的余数即可. In…
康托展开 裸的康托展开&逆康托展开 康托展开就是一种特殊的hash,且是可逆的…… 康托展开计算的是有多少种排列的字典序比这个小,所以编号应该+1:逆运算同理(-1). 序列->序号:(康托展开) 对于每个数a[i],数比它小的数有多少个在它之前没出现,记为b[i],$ans=1+\sum b[i]* (n-i)!$ 序号->序列:(逆康托展开) 求第x个排列所对应的序列,先将x-1,然后对于a[i],$\left\lfloor \frac{x}{(n-i)!} \right\rflo…
[题解] 我们可以轻松想到朴素的状态转移方程,但直接这样做是n^2的.所以我们考虑采用树状数组优化.写法跟求逆序对很相似,即对前缀和离散化之后开一个权值树状数组,每次f[i]+=query(sum[i]),再把f[i]加入到sum[i]位置上.这样可以保证每次f[i]加上的是在它前面的.sum小于它的位置的f值. #include<cstdio> #include<algorithm> #define N 200010 #define rg register #define Mod…
思路: 动态规划.首先处理出这些数的前缀和$a$,$f_i$记录从第$1$位到第$i$位的最大分组数量.DP方程为:$f_i=max(f_i,f_j+1)$,其中$j$满足$a_i-a_j≥0$. #include<cstdio> #include<cstring> #include<algorithm> int main() { int n; scanf("%d",&n); ]; a[]=; ]; memset(f,,sizeof f);…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 67  Solved: 39[Submit][Status] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer John. The co…
3301: [USACO2011 Feb] Cow Line Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 82  Solved: 49[Submit][Status][Discuss] Description The N (1 <= N <= 20) cows conveniently numbered 1...N are playing yet another one of their crazy games with Farmer Joh…
2272: [Usaco2011 Feb]Cowlphabet 奶牛文字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 97[Submit][Status][Discuss] Description Like all bovines, Farmer John's cows speak the peculiar 'Cow'language. Like so many languages, each word in this…
3300: [USACO2011 Feb]Best Parenthesis Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 42[Submit][Status] Description Recently, the cows have been competing with strings of balanced parentheses and comparing them with each other to see who…
题目 1633: [Usaco2007 Feb]The Cow Lexicon 牛的词典 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 401  Solved: 216[Submit][Status] Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw"…
http://www.lydsy.com/JudgeOnline/problem.php?id=3301 其实这一题很早就a过了,但是那时候看题解写完也是似懂非懂的.... 听zyf神犇说是康托展开,然后拖到今天才来看看... sad.. 从不知道那里来的文档里边抄的: 康托展开就是一种特殊的哈希函数,它的使用范围是对于n个数的排列进行状态的压缩和存储.X=a[n]*(n-1)!+a[n-1]*(n-2)!+…+a[i]*(i-1)!+…+a[2]*1!+a[1]*0! 其中,a为整数,并且0<…
康拓展开/逆展开 模板 #include<algorithm> #include<iostream> #include<cstdio> #define int long long using namespace std; inline int rd(){ int ret=0,f=1;char c; while(c=getchar(),!isdigit(c))f=c=='-'?-1:1; while(isdigit(c))ret=ret*10+c-'0',c=getcha…
原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=3301 康拓展开和逆展开的模板题. #include<iostream> #include<cstring> #include<cstdio> #define maxn 21 using namespace std; inline int read(){ register int x(0),f(1); register char c(getchar()); whi…
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer A_i (-10,000 <= A_i <= 10,000). FJ knows t…
题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row and numbered 1..N. The cows are conducting another one of their strange protests, so each cow i is holding up a sign with an integer A_i (-10,000 <= A_i <= 10,000). FJ knows t…
Description 没有几个人知道,奶牛有她们自己的字典,里面的有W (1 ≤ W ≤ 600)个词,每个词的长度不超过25,且由小写字母组成.她们在交流时,由于各种原因,用词总是不那么准确.比如,贝茜听到有人对她说"browndcodw",确切的意思是"browncow",多出了两个"d",这两个"d"大概是身边的噪音. 奶牛们发觉辨认那些奇怪的信息很费劲,所以她们就想让你帮忙辨认一条收到的消息,即一个只包含小写字母且长…
http://www.lydsy.com/JudgeOnline/problem.php?id=1633 一开始也想到了状态f[i]表示i以后的字符串最少删的数 然后想到的转移是 f[i]=min{f[i+1]+1, f[i+len[a]]} 但是没想到....后边其实不是完全匹配到整个单词,,而是可以删的.. 那么就转换一下,. f[i]=min{f[i+1]+1, f[i+len[a]+t]+t} t为i开始后找到单词a要删的字母个数.. 这里可以优化,当a[0]==b[i]时,才进行转移.…
题目描述 Like all bovines, Farmer John's cows speak the peculiar 'Cow'language. Like so many languages, each word in this language comprisesa sequence of upper and lowercase letters (A-Z and a-z).  A wordis valid if and only if each ordered pair of adjac…
Description Recently, the cows have been competing with strings of balanced  parentheses and comparing them with each other to see who has the  best one.  Such strings are scored as follows (all strings are balanced): the  string "()" has score…
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1633 [题目大意] 给出一个字符串和一个字符串集, 问要删去多少个字符该字符串才可以被字符串集完全表示 [题解] dp[i]表示长度为i时候的答案,单调dp即可 [代码] #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int N=101…
http://www.lydsy.com/JudgeOnline/problem.php?id=3300 这个细节太多QAQ 只要将所有的括号'('匹配到下一个')'然后dfs即可 简单吧,,, #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> #include…
f[i]=min{f[i+1]+1,f[i+len[j]+cant]+cant}(for i=L-1 downto 0)(1<=j<=w) #include<cstdio> #include<iostream> #include<string> using namespace std; int n,m; string s,words[601]; int f[302]; int main() { scanf("%d%d",&n,&a…
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1633 题意: 给你一个长度为n的主串a,和一个有m个字符串s[i]的单词书(s[i].size <= 25). 问你至少删去多少个a中的字符,才能使a成为一个由s[i]组成的排列. 题解: 从后往前推. 表示状态: dp[i] = min eliminations 表示第i个及以后的字符合法时,删去字符的最小数量. 找出答案: ans = dp[0] 整个串合法. 如何转移: 对于第i个…
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=118 传送门2:http://www.lydsy.com/JudgeOnline/problem.php?id=2590 又挂了一道贪心,好烦啊. 这一题应该要想到“撤回”操作就好办了.假设现在已经没有优惠券了,那么如果你想以优惠价格买下一头牛,就要撤回以前的用优惠券买的牛,具体就是加回p[i] - c[i]就行了,可以理解为花这么多钱买一张优惠券.然后就是维护3个小根堆了.…
n<=250个大写字母和m<=250个小写字母,给p<=200个合法相邻字母,求用这些合法相邻字母的规则和n+m个字母能合成多少合法串,答案mod 97654321. 什么鬼膜数.. f(i,j,k)--i个大写字母,j个小写字母,最后一个字母是k,,其中k是小写字母,p是能接在k前面的任意字母,k是大写字母的话同理. 这样复杂度是n*m*26*26?假的!i,j确定后只有p种合法转移,所以就n*m*p. trick:记得算i=0和j=0的情况!!! #include<cstrin…
预处理出g[i][j]表示原串第i个匹配第j个单词需要去掉几个字母(匹配不上为-1) 设f[i]为i及之后满足条件要去掉的最少字母 倒着dp! f[i]初始为f[i+1]+1,转移方程为f[i]=min(f[i],f[i+strlen(b[j]+1)+g[i][j]]+g[i][j]) 也不是很难理解但是这个思路挺难想到的吧感觉-- #include<iostream> #include<cstdio> #include<cstring> using namespace…
这是我今天遇到最奇怪的问题,希望有人帮我解释一下... 一开始我能得90分: #include<iostream> #include<cstdio> #include<cmath> #include<ctime> #include<queue> #include<algorithm> #include<stack> #include<cstring> using namespace std; #define d…