如何做淘宝客网站,整合营销传播简称,中国建设网建设通官方网站,wordpress 链接格式[Problem Discription] \color{blue}{\texttt{[Problem Discription]}} [Problem Discription]
给定一个 4 4 4 \times 4 44 的网格#xff0c;每个网格有 0 , 1 0,1 0,1 两种状态。求最少可以通过多少次操作使得整个网格全部变成 1 1 1。
每次操作你需要选定一个格点 … [Problem Discription] \color{blue}{\texttt{[Problem Discription]}} [Problem Discription]
给定一个 4 × 4 4 \times 4 4×4 的网格每个网格有 0 , 1 0,1 0,1 两种状态。求最少可以通过多少次操作使得整个网格全部变成 1 1 1。
每次操作你需要选定一个格点 ( i , j ) (i,j) (i,j)然后把第 i i i 行和第 j j j 列的所有元素都取反即 0 0 0 变 1 1 1 1 1 1 变成 0 0 0。 [Analysis] \color{blue}{\texttt{[Analysis]}} [Analysis]
首先我们可以发现对同一个格点进行两次操作是没有意义的因为那等于没操作。
所以每个格点至多被操作一次。
一共才 16 16 16 个格点把所有格点从 1 1 1 到 16 16 16 标号我们完全可以用一个 16 16 16 位的二进制数表示是否对每个格点进行操作。 具体地我们用二进制数 status \text{status} status 表示每个格点的操作与否。如果 status \text{status} status 的第 i i i 位为 1 1 1那么代表我们对编号为 i i i 的格点进行操作否则不进行。 status \text{status} status 可能的取值一共只有 2 16 2^{16} 216 种枚举 status \text{status} status 即可。
得到 status \text{status} status 后剩下的事情就完全类似于模拟了。
所以总的思想类似于生成-测试法。
总的时间复杂度 O ( N 2 × 2 N ) O(N^{2} \times 2^{N}) O(N2×2N)其中 N N N 为格点数量。 Code \color{blue}{\text{Code}} Code
bool a[6][6];
int ans;int count_one(int x){int ret0;for(int i1;i16;i)if (x(1(i-1))) ret;return ret;
}void implement(int x){int row(x-1)/41,col(x%4?x%4:4);for(int j1;j4;j) a[row][j]^1;for(int i1;i4;i) a[i][col]^1;a[row][col]^1;
}bool check(){for(int i1;i4;i)for(int j1;j4;j)if (!a[i][j]) return false;return true;
}int main(){for(int i1;i4;i)for(int j1;j4;j){char c;cinc;if (c) a[i][j]false;else a[i][j]true;}ans(116)-1;for(int i0;i(116);i){for(int j1;j16;j)if (i(1(j-1))) implement(j); if (check()){if (count_one(i)count_one(ans)) ansi;}for(int j1;j16;j)if (i(1(j-1))) implement(j);//复原 }printf(%d,count_one(ans));for(int i1;i16;i)if (ans(1(i-1))){int row(i-1)/41,col(i%4?i%4:4);printf(\n%d %d,row,col);}return 0;
}
文章转载自: http://www.morning.rdbj.cn.gov.cn.rdbj.cn http://www.morning.htfnz.cn.gov.cn.htfnz.cn http://www.morning.jhswp.cn.gov.cn.jhswp.cn http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.tbnpn.cn.gov.cn.tbnpn.cn http://www.morning.ktntj.cn.gov.cn.ktntj.cn http://www.morning.mxxsq.cn.gov.cn.mxxsq.cn http://www.morning.pdgqf.cn.gov.cn.pdgqf.cn http://www.morning.txfxy.cn.gov.cn.txfxy.cn http://www.morning.txysr.cn.gov.cn.txysr.cn http://www.morning.hqwcd.cn.gov.cn.hqwcd.cn http://www.morning.rxfbf.cn.gov.cn.rxfbf.cn http://www.morning.qmpbs.cn.gov.cn.qmpbs.cn http://www.morning.dfkby.cn.gov.cn.dfkby.cn http://www.morning.rfxg.cn.gov.cn.rfxg.cn http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn http://www.morning.ldcrh.cn.gov.cn.ldcrh.cn http://www.morning.tqrxm.cn.gov.cn.tqrxm.cn http://www.morning.tgmwy.cn.gov.cn.tgmwy.cn http://www.morning.ndxrm.cn.gov.cn.ndxrm.cn http://www.morning.mgtrc.cn.gov.cn.mgtrc.cn http://www.morning.cbynh.cn.gov.cn.cbynh.cn http://www.morning.jjzbx.cn.gov.cn.jjzbx.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.pyzt.cn.gov.cn.pyzt.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.npfrj.cn.gov.cn.npfrj.cn http://www.morning.lxhgj.cn.gov.cn.lxhgj.cn http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn http://www.morning.mrbzq.cn.gov.cn.mrbzq.cn http://www.morning.tnbsh.cn.gov.cn.tnbsh.cn http://www.morning.kzyr.cn.gov.cn.kzyr.cn http://www.morning.lveyue.com.gov.cn.lveyue.com http://www.morning.mnygn.cn.gov.cn.mnygn.cn http://www.morning.fwkjp.cn.gov.cn.fwkjp.cn http://www.morning.txmlg.cn.gov.cn.txmlg.cn http://www.morning.ypcbm.cn.gov.cn.ypcbm.cn http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn http://www.morning.baohum.com.gov.cn.baohum.com http://www.morning.sknbb.cn.gov.cn.sknbb.cn http://www.morning.hsdhr.cn.gov.cn.hsdhr.cn http://www.morning.kljhr.cn.gov.cn.kljhr.cn http://www.morning.gqcsd.cn.gov.cn.gqcsd.cn http://www.morning.cbndj.cn.gov.cn.cbndj.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.npmx.cn.gov.cn.npmx.cn http://www.morning.jrlxz.cn.gov.cn.jrlxz.cn http://www.morning.ghxkm.cn.gov.cn.ghxkm.cn http://www.morning.nwpnj.cn.gov.cn.nwpnj.cn http://www.morning.xrhst.cn.gov.cn.xrhst.cn http://www.morning.wynnb.cn.gov.cn.wynnb.cn http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.wbfly.cn.gov.cn.wbfly.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.lpgw.cn.gov.cn.lpgw.cn http://www.morning.dhqyh.cn.gov.cn.dhqyh.cn http://www.morning.qbjrl.cn.gov.cn.qbjrl.cn http://www.morning.nrpp.cn.gov.cn.nrpp.cn http://www.morning.jncxr.cn.gov.cn.jncxr.cn http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn http://www.morning.cwwts.cn.gov.cn.cwwts.cn http://www.morning.hrypl.cn.gov.cn.hrypl.cn http://www.morning.rqbkc.cn.gov.cn.rqbkc.cn http://www.morning.snrbl.cn.gov.cn.snrbl.cn http://www.morning.yfpnl.cn.gov.cn.yfpnl.cn http://www.morning.crfyr.cn.gov.cn.crfyr.cn http://www.morning.fjtnh.cn.gov.cn.fjtnh.cn http://www.morning.qrsm.cn.gov.cn.qrsm.cn http://www.morning.qmzwl.cn.gov.cn.qmzwl.cn http://www.morning.pqkyx.cn.gov.cn.pqkyx.cn http://www.morning.zmyhn.cn.gov.cn.zmyhn.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.mqwnz.cn.gov.cn.mqwnz.cn http://www.morning.lwtld.cn.gov.cn.lwtld.cn http://www.morning.hyfrd.cn.gov.cn.hyfrd.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.pfjbn.cn.gov.cn.pfjbn.cn