codevs 2218 [CTSC1999] 补丁vs错误 dfs+二进制
2017-10-23 21:20
260 查看
题目:
http://codevs.cn/problem/2218/
暴搜+剪枝;
x & ~ ( 1 << i ) : 将集合x中的元素i去除;
( x & i ) == i , 判断i是否为x的子集 ;
教训:
考虑用中间变量来解决;
(感谢loi_wzhd大佬 orz);
http://codevs.cn/problem/2218/
暴搜+剪枝;
x & ~ ( 1 << i ) : 将集合x中的元素i去除;
( x & i ) == i , 判断i是否为x的子集 ;
教训:
x=x&~ss[i].s4; x=x|ss[i].s3; dfs(tot+ss[i].tim,x); x=x|ss[i].s4;//可能把没减的也加上了; x=x&~ss[i].s3;
考虑用中间变量来解决;
(感谢loi_wzhd大佬 orz);
#include<iostr 4000 eam> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; const int MAXN=101; int n,m,ans=2147483647; bool vis[400001]; struct hh { int tim,s1,s2,s3,s4; }ma[MAXN]; void dfs(int tot,int x) { if(tot>=ans || vis[x]) return;//不加T五组,加了跑44ms; if(!x) {ans=tot;return;} vis[x]=1; for(int i=1;i<=m;i++) { int v; if( (ma[i].s1 & x)==ma[i].s1 && !(ma[i].s2 & x)) { v=x&~ma[i].s4,v|=ma[i].s3;//需要一个中间变量; dfs(tot+ma[i].tim,v); } } vis[x]=0; return; } void solve() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { string s1,s2; scanf("%d",&ma[i].tim); cin>>s1>>s2; for(int j=0;j<n;j++) { if(s1[j]=='+') ma[i].s1^=1<<j; else if(s1[j]=='-') ma[i].s2^=1<<j; } for(int j=0;j<n;j++) { if(s2[j]=='+') ma[i].s3^=1<<j; else if(s2[j]=='-') ma[i].s4^=1<<j; } } dfs(0,(1<<n)-1); cout<<(ans==2147483647?0:ans); return; } int main() { solve(); return 0; }
相关文章推荐
- 【CTSC1999】 CODE[VS] 2218 补丁VS错误(状压最短路)
- 【codevs 2218】补丁vs错误(CTSC 1999)
- codevs2218 补丁vs错误 1999年CTSC国家队选拔赛[三星]
- 【codevs 2218】补丁vs错误(CTSC 1999)
- 【状压bfs】ctsc 1999 补丁vs错误
- CTSC1999补丁VS错误题解
- codevs2218 补丁VS错误(状压+spfa更新)
- codevs 2218 补丁vs错误(状压搜索)(luogu P1527)
- 【CTSC1999】补丁vs错误 状压最短路
- CTSC1999补丁VS错误题解
- codevs 2218 补丁vs错误
- 2218 补丁vs错误
- codevs 2218 补丁 vs 错误 (最短路)
- codevs 2218 补丁vs错误(状压搜索)
- 补丁vs错误(codevs 2218 错误答案)
- 家园 codevs1034 ctsc1999 最大流
- 等价表达式(codevs 1107 答案错误)
- [NOIP1999提高] CODEVS 1047 邮票面值设计(dfs+dp)
- vscode无法检查到vue文件里的语法错误
- VSCode Markdown PDF 导出成 PDF 报 phantomjs binary does not exist 错误的解决办法