博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj3380[Usaco2004 Open]Cave Cows 1 洞穴里的牛之一*
阅读量:6871 次
发布时间:2019-06-26

本文共 1256 字,大约阅读时间需要 4 分钟。

题意:

给一个无向图,每一条边都有一个阈值,有一些点有草。牛从点1出发,每当它到达有草的点可以选择吃或不吃,如果吃的话体重加1。对于边如果它的阈值小于牛的体重,则此边不可通过。求牛走一圈回到点1的最大体重。有草节点数≤14。点数≤100,边数≤1000。

题解:

f[i][S]表示当前点为i,草状态为S的状态能否达到。具体看代码。

代码:

1 #include 
2 #include
3 #include
4 #define inc(i,j,k) for(int i=j;i<=k;i++) 5 #define maxn 110 6 using namespace std; 7 8 inline int read(){ 9 char ch=getchar(); int f=1,x=0;10 while(ch<'0'||ch>'9'){
if(ch=='-')f=-1; ch=getchar();}11 while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();12 return f*x;13 }14 struct e{
int t,w,n;}es[maxn*20]; int g[maxn],ess;15 void pe(int f,int t,int w){16 es[++ess]=(e){t,w,g[f]}; g[f]=ess; es[++ess]=(e){f,w,g[t]}; g[t]=ess;17 }18 bool vis[maxn][17000]; int ans,a[17000],n,m,k,b[maxn];19 void dfs(int x,int y){20 if(vis[x][y])return; vis[x][y]=1; if(x==1)ans=max(ans,a[y]);21 if(b[x]&&(y&(1<<(b[x]-1))))dfs(x,y^(1<<(b[x]-1)));22 for(int i=g[x];i;i=es[i].n)if(es[i].w>=a[y])dfs(es[i].t,y);23 }24 int main(){25 n=read(); m=read(); k=read(); inc(i,1,k){
int x=read(); b[x]=i;}26 inc(i,1,m){
int x=read(),y=read(),z=read(); pe(x,y,z);}27 inc(i,0,(1<
<

 

20160909

转载于:https://www.cnblogs.com/YuanZiming/p/5876493.html

你可能感兴趣的文章
[原]虚拟机(ubuntu)无法ping通主机
查看>>
android Build系统
查看>>
HTML5本地存储——IndexedDB(一:基本使用)
查看>>
Android Studio HelloWorld
查看>>
Windows命令点滴
查看>>
BZOJ-1040: [ZJOI2008]骑士 (树形DP)
查看>>
MS CRM 2011的自定义和开发(10)——CRM web服务介绍(第二部分)——IOrganizationService(二)...
查看>>
【Summary】ANSYS TRANSIENT ANALYSIS
查看>>
Unity3D性能优化--- 收集整理的一堆
查看>>
全面理解Unity加载和内存管理
查看>>
JMeter接口测试示例(二)
查看>>
swift -- 单例+ lazy懒加载 + 第三方库
查看>>
The Zen of Python, by Tim Peters
查看>>
SQL日期格式转换
查看>>
移动互联网下半场的面试真经,让你进入 BAT 不再是梦
查看>>
Windows 下 Hbuilder 真机调试(Android,iphone)
查看>>
async和await
查看>>
称霸Kaggle的十大深度学习技巧
查看>>
只需3步,即可将你的Chromium Edge 浏览器设置成中文
查看>>
【270】IDL处理GeoTIFF数据
查看>>