E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
Kefa
Kefa
and Park(DFS、实现)
文章目录题面链接题意题解代码总结题面链接C.KefaandPark题意求叶节点数量,叶节点满足,从根节点到叶节点的路径上最长连续1的长度小于m题解这道题目主要是实现,当不满足条件时直接返回。到达叶节点后统计答案,用vector存图的话,无向图时,叶节点的边只有一条,也就是g[i].size()==1g[i].size()==1g[i].size()==1而不是0需要特判是一条链的情况,一条链的话根
wa的一声哭了
·
2024-02-13 15:33
codeforces
算法
c++
mybatis
django
java
spring
boot
spring
Kefa
and First Steps(DP)
Problem-580A-Codeforces#includeusingnamespacestd;constintN=1e5+5;intn,a[N],res;intmain(){scanf("%d",&n);for(inti=1;i=a[i-1])cnt++;elsecnt=0;res=max(res,cnt);}cout<<res+1;return0;}
陈进士学习
·
2023-11-07 01:52
codeforces
算法
c++
数据结构
c语言
开发语言
贪心
Kefa
and Park
Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa'shouse.Unfortunaelyforourhero
weixin_30686845
·
2023-09-30 01:41
【CF580C】
Kefa
and Park dfs
KefaandParkdfs题目大意题目链接代码题目大意Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa’s
不可知论大祭司
·
2023-09-30 01:41
树形结构
dfs
Kefa
and Park
给您带来优质的代码体验,给您带来欢喜^_^题目传送门C.KefaandParktimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helives
pioneer 1
·
2023-09-30 01:10
深度优先搜索(dfs)
题
Kefa
and Park dfs
C.KefaandParkTimeLimit:1SecMemoryLimit:256MB题目连接http://codeforces.com/contest/580/problem/CDescriptionKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisaroo
weixin_30443075
·
2023-09-30 01:10
数据结构与算法
CF580C
Kefa
and Park dfs
Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa'shouse.Unfortunaelyforourhero
looooooogn
·
2023-09-30 01:10
Kefa
and Park (树的dfs)
Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa'shouse.Unfortunaelyforourhero
h1021456873
·
2023-09-30 01:08
codeforces
dfs
Kefa
and Park
Kefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa'shouse.Unfortunaelyforourhero
Harzer
·
2023-09-30 01:08
c++
蓝桥杯
算法
Kefa
and Park
C.KefaandParktimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisa
zhaohuc
·
2023-09-30 01:38
DFS
codeforces
ACM
算法
codeforces
DFS
Kefa
and Park - dfs判重
1.题目描述:C.KefaandParktimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.The
寒江雪里独钓着的蓑笠翁
·
2023-09-30 01:38
DFS
acm
codeforces
Kefa
and Park【dfs】
C.KefaandParktimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisa
飘摇的尘土
·
2023-09-30 01:08
搜索
codeforces580C.
Kefa
Kefa
and Park
ProblemKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisarootedtreeconsistingofnverticeswiththerootatvertex1.Vertex1alsocontainsKefa’shouse.Unfortunaelyfor
EDGBittersweet
·
2023-09-30 01:37
Codeforces
Kefa
and Park time limit per test
C.KefaandParktimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefadecidedtocelebratehisfirstbigsalarybygoingtotherestaurant.Helivesbyanunusualpark.Theparkisa
雨狮子
·
2023-09-30 01:36
ACM_搜索
DFS
Kefa
and Park(dfs&tree)
KefaandPark-洛谷Problem-580C-CodeforcesExamplesinput411100121314output2input711011000121324253637output2解析:dfs遍历,记录前一个结点权值是否为1,并且累计路径1的个数。#includeusingnamespacestd;#defineintlonglongconstintN=1e5+5;intn
陈进士学习
·
2023-09-30 01:05
codeforces
深度优先
c语言
图论
算法
c++
数据结构
[基础DP][CF580A]
Kefa
and First Steps(最长不下降子序列)
CF-580A题目大意求最长的连续不下降子序列。题目分析设f[x]表示以x这个位置结尾的最长不下降子序列的长度,那么f[x-1]与f[x]的关系很显然取决于a[x]与a[x-1]的关系.如果a[x]>=a[x-1],显然要f[x]=f[x-1]+1;否则f[x]=1,从头再来。扫描一遍,以1~n结尾的最长连续不下降子序列,得到最大的那个就可以了。参考代码#includeusingnamespace
沧海无雨
·
2023-03-13 00:29
Kefa
and Dishes (状压dp)
D.KefaandDishestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendis
whai362
·
2020-09-14 21:37
动态规划
Kefa
and Dishes(状压dp)
题意$n$个食物,每个食物有一个满意度,从中选出$m$个,使得满意度最大同时有$k$个关系:若$x_i$在$y_i$之前吃,则会获得$C_i$的收益Sol官方题解是$O(2^nn^2)$的,不过我没发现状态之间的联系,就写了一个$O(2^nn^3)$的,不过还是水过去了。$f[i][j][sta]$表示现在已经放了$i$个,本轮要放第$j$个,状态为$sta$转移的时候枚举一下上一个放了什么/**
oldbalck
·
2020-09-14 21:21
Kefa
and Dishes
timelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsth
weixin_30853329
·
2020-09-14 20:00
codeforces 580D
Kefa
and Dishes
传送门:http://codeforces.com/problemset/problem/580/d思路:状压DP,f[i][j]表示最后一个为i,已选取的菜的状态为j。#include#include#includeconstintmaxt=540000;usingnamespacestd;typedeflonglongll;intn,m,k,g[20][20],a[20],pow[20];ll
weixin_30266829
·
2020-09-14 20:53
Codeforces 580D
Kefa
and Dishes
题意:给你n道菜吃,每道菜都能获得a[i]个满意度,此外还有m个规则,在吃y之前吃x能多获得c的满意度,问你如何点菜能获得最多的满意度。思路:看到n只有18,而且还要求最多的满意度。直接状压DP,dp[i][j]表示当前正要吃第i道菜,且状态为s。然后只要三重循环枚举。一重枚举状态s,从0~(1#include#includeusingnamespacestd;typedef__int64LL;c
金金金金鑫
·
2020-09-14 20:35
2016个人训练赛1
Kefa
and Dishes CodeForces - 580D
http://codeforces.com/problemset/problem/580/D状压DP裸题dp[i][j]代表状态i下以第j道菜为结尾时的最大满意度当某一状态恰好有m道菜时更新一下答案即可#includeusingnamespacestd;typedeflonglongll;constintmaxn=20;constintmaxm=1e6+10;lldp[maxm][maxn];ll
sunyutian1998
·
2020-09-14 20:07
状压DP
CodeForces
状压DP
CF580D,
Kefa
and Dishes(状压DP)
题意:有n道菜,每道菜一个权值,有k个条件,表示第y道菜在第x道后马上吃有c的附加值。求从中吃m道菜的最大权值。本题详解可看:https://www.cnblogs.com/real-l/p/8597827.html作为还在入门状压DP的萌新,这里就分析一下怎么推出DP状态。首先,n的范围比较小,且每道菜有个吃与不吃操作,可用二进制1,0表示,故不难相处可用状压DP;其次,n道菜就有1#inclu
shamansi99
·
2020-09-14 20:31
状压DP
状压DP
状压dp Codeforces580D
Kefa
and Dishes
传送门:点击打开链接题意:有n种菜,现在选m种菜来吃,还有很多条好处,如果在吃y的前一道菜是x的话,那么就可以获得满意度。每一种菜都有一个满意度。思路:...只能说Codeforces的测评机实在是太好了,n=18,O(n^2*2^n)复杂度的记忆化搜索代码都能在500ms跑出来,我自己本地跑了3秒多--如果你敢写O(n^2*2^n)复杂度的代码的话,那基本就做完了。设dp[i][S]表示为最后一
逍遥丶綦
·
2020-09-14 20:37
ACM_DP
Codeforces580D
Kefa
and Dishes
看完题目还是一脸蒙,百度了半天,看了好几个AC代码才勉强写(凑)出来。题意很简单,菜单上有n道菜,你可以点m样,每样菜有它自己的幸福感,然后还加入了k个规则,比如在吃了第i样菜之后,再吃第j样菜,可以获得c的幸福感,问最大的幸福感。1usingnamespacestd;typedeflonglongll;constintmaxn=20;constintmaxnn=(1>n>>m>>k;for(in
Nero Alix
·
2020-09-14 20:46
DP
CF580D
Kefa
and Dishes
CF580DKefaandDishes题解这题是用来智力康复的。。。设f[S][i]f[S][i]f[S][i]为当前已选菜的状态为S,最后一个菜为i的最大满意度然后转移即可code:#include#defineintlonglongusingnamespacestd;intn,m,k,a[25],val[25][25],f[(1<<18)+5][25];signedmain(){scanf("
lahlah_
·
2020-09-14 19:23
DP
CodeForces 580D (状压DP)
Kefa
and Dishes
点击打开链接题意:有n盘菜,从里面选m盘可以品尝,每盘菜有一个满意值,另外有k种关系,先吃某盘菜后吃某盘的话可以增加ai满意度。思路:约束条件有当前吃的哪盘菜,在吃这盘菜之前吃了哪几盘菜,所以定义状态是dp[i][j],表示当前让第i盘菜作为吃的最后一盘时,已经吃了菜的集合为j,获得的最大满意度;用n位2进制表示状态,1表示吃过了这盘菜,0表示没吃,状态转移方程:dp[i][j]=max(dp[i
莫比乌斯灯泡
·
2020-09-14 19:15
动态规划
Kefa
and Company(前缀和,二分查找)
B.KefaandCompanytimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputKefawantstocelebratehisfirstbigsalarybygoingtorestaurant.However,heneedscompany.Kefahasnfrie
luciozhang
·
2020-09-14 19:08
Codeforces
高效算法
CF 580D
Kefa
And Dishes 状压DP
题意:n件物品,第i件物品价值为a[i].现在要选m件物品.有k个加成,若物品x正好在物品y的前一个则总价值+a[x][y]mj)的边权值为(a[i]+c[i][j]).现在就是找到一条长度为m-1并且权值最大的路径.明显状压.设dp[s][u]表示在u点,并且经过的点的状态为s.dp[s][u]+a[j]+c[u][j]->dp[s|2^j][j](u在s并且j不再s)res=max(res,d
orz11111111
·
2020-09-14 19:55
DP
Codeforces
泛做
Codeforces,
Kefa
and Dishes,状态压缩DP
题意:给定n个物品,每个物品都有一个满意度v,现在从n个物品中选取m个,选的过程中有几个规则,它们是基于选择顺序给出的规则,例如:选择的过程中a和b相邻,且a在b的前面,则满意度增加c,现在给出了k个这样的规则。问你根据这些规则,从n个物品中选取m个的最大满意度是多少。范围:0#include#include#include#include#include#include#includeusing
lishuandao
·
2020-09-14 19:15
Codeforces
codeforces 580D
Kefa
and Dishes【状态压缩+dp】
题目大意:n个菜中选m个菜吃,每个菜有一个满意度ai,此外有k种情况:先吃xi再吃yi会额外增加ci满意度。问最大满意度。思路:数组dp[1#include#include#includeusingnamespacestd;typedef__int64LL;constintMAXN=20;LLsat[MAXN];LLmap[MAXN][MAXN];LLdp[1>n>>m>>k;for(inti=0
lhfl911
·
2020-09-14 19:32
dp
Kefa
and Dishes(CodeForces580D)[状态压缩DP]
状态压缩DP裸题,比赛的时候没反应过来,进行了n次枚举起点的solve,导致超时。#include#include#include#includeusingnamespacestd;intn,m,k;intcost[20][20],val[20];inta,b,c;longlongdp[1hhh[19];intjudge(intx){intres=0;while(x!=0){if(x&1)res+
dmqocbae156792
·
2020-09-14 18:25
codeforces 580D:
Kefa
and Dishes
DescriptionWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthatheneedsexactlymdishes.Butatthat,hedoesn'twanttoorderthesamedishtwicetotasteasma
dgoh41514
·
2020-09-14 18:48
Kefa
and Dishes
D.KefaandDishes题目链接给一个序列ai,长度为n,每个ai对应一个价值,选出m个数字出来,同时给出K对关系(i,j,ck)表示当前如果取了第j个,而上次是取的第i个,那么还可以获得ck的价值,问最大能获得的价值。m#include#include#include#include#include#include#include#include#include#include#inclu
WeYoungg
·
2020-09-14 18:38
CF
DP
Kefa
and Dishes (状压dp)
传送门题目大意:有n个菜,每个菜只能吃一次,最多吃m个,每盘菜都有一个快乐值,吃菜的先后顺序也会增加快乐值。解题思路:一开始尝试用最小费用最大流,最后建了一个很复杂的图,发现并不是很好建出来,遂放弃,后来看了别人的写法状压dp,太菜了啊。dp[i][j],i二进制代表现在吃的菜的状态,1代表吃了,0代表没吃,j代表最后吃的j,这样达到的最高快乐值。由当前的dp[s][j],可以去更新后面的状态,在
给我一瓶AC钙
·
2020-09-14 18:28
CodeForces
动态规划
Kefa
and Dishes CodeForces - 580D (dp 状态压缩)
WhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthatheneedsexactlymdishes.Butatthat,hedoesn'twanttoorderthesamedishtwicetotasteasmanydishesasp
日月火山
·
2020-09-14 18:27
dp
Kefa
and Dishes (状态转移dp)
题意:一个人去点餐从n种点出m种。每一种菜都会有一个满意度,并且他制订了k个规则,若a在b之前吃的话,会额外得到满意度。求出最大满意度。思路:由于问题的规模不大(1 ≤ m ≤ n ≤ 18,0 ≤ k ≤ n * (n - 1)),所以很明显要用到状态转移dp,若何用呢?想到需要一个状态st表示菜的选择状态,i表示以第i种菜为结尾的最大值,则遍历st的每一种情况去求出dp[st][i].#inc
cyl纤云弄巧
·
2020-09-14 18:22
dp
Codeforces
[codeforces 580D]
Kefa
and Dishes
n很小,很容易想到状态压缩dp,用dp[set][i]表示结尾是i,用了set里的元素的最大值,枚举set和i来更新下一个元素即可。#include#include#include#includeusingnamespacestd;longlongval[20],dp[300000][20];longlongn,m,k;sets;longlongmax(longlongx,longlongy){r
MaticsL
·
2020-09-14 18:44
DP
580D -
Kefa
and Dishes
WhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthatheneedsexactlymdishes.Butatthat,hedoesn'twanttoorderthesamedishtwicetotasteasmanydishesasp
让我改变你的心智
·
2020-09-14 18:37
DP
codeforces
hdu
Kefa
and Dishes(状压DP)
KefaandDishesTimeLimit:2000MSMemoryLimit:262144KB64bitIOFormat:%I64d&%I64uSubmitStatusDescriptionWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefakn
mrcoderrev
·
2020-09-14 18:03
状压DP
CF580D_
Kefa
and Dishes
D.KefaandDishestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendis
weixin_33939380
·
2020-09-14 17:45
Kefa
and Dishes (状态压缩DP)
题目:http://codeforces.com/contest/580/problem/D题意:有n种菜(每一种菜有一个满意值ai>=0),你准备吃m种,每种一次。但是如果你按某种规则吃两种菜的话会增加额外的满意值,比如规则(xiyici)就是你先吃第xi个菜,然后马上吃第yi个菜,那么你就会额外增加ci点满意值。有k个这样的规则,问你吃m种菜后的最大满意值是多少。分析:定义dp[i][j],i
w20810
·
2020-09-14 17:33
ACM-动态规划
CodeForces 580D.
Kefa
and Dishes(状压DP)
D.KefaandDishestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendis
Usher_Ou
·
2020-09-14 17:33
CF
数据结构
状压DP
Kefa
and Dishes CodeForces - 580D
传送门题目:WhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthatheneedsexactlymdishes.Butatthat,hedoesn'twanttoorderthesamedishtwicetotasteasmanydis
qq_2456160268
·
2020-09-14 17:52
ACM
dp
CF 580D
Kefa
and Dishes(简单状压dp)
题目链接WhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthatheneedsexactlymdishes.Butatthat,hedoesn'twanttoorderthesamedishtwicetotasteasmanydishe
飞不起的弱鸡
·
2020-09-14 17:08
DP
Kefa
and Dishes(DP,掩码)
D.KefaandDishestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendis
luciozhang
·
2020-09-14 17:35
动态规划
Codeforces
acm
codeforces
dp
掩码
CodeForces - 580D
Kefa
and Dishes
CodeForces-580DKefaandDishes状压dp,但是这不是关键,关键是ans我忘了是longlong了,然后%d输出的,整个代码改来改去一直WA在test7……WhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendishes.Kefaknowsthath
mandiheyanyu
·
2020-09-14 17:24
Kefa
and Dishes (状态压缩dp)
D.KefaandDishestimelimitpertest2secondsmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputWhenKefacametotherestaurantandsatatatable,thewaiterimmediatelybroughthimthemenu.Therewerendis
zthgreat
·
2020-09-14 17:41
【动态规划】
dp
压缩
Kefa
and Dishes(状压dp)
题意:有n盘菜,现在你要吃m盘菜,每种菜只能吃一次吃第i盘菜可以得到a(i)的满足感,同时给出k条规则(x,y,c),表示如果在吃y之前刚好吃过了x,那么就会得到c的满足感,(注意x和y之间没有其他菜)问吃m盘菜的最大满足感是多少.数据范围:nusingnamespacestd;#defineintlonglongconstintmaxm=20;vector>g[20];intd[1>n>>m>>
这有点难啊
·
2020-08-24 11:17
Kefa
and Watch (字符串hash + 线段树)
E.KefaandWatchtimelimitpertest1secondmemorylimitpertest256megabytesinputstandardinputoutputstandardoutputOnedayKefatheparrotwaswalkingdownthestreetashewasonthewayhomefromtherestaurantwhenhesawsomethin
whai362
·
2020-08-15 12:55
数据结构
上一页
1
2
3
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他