青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 87  文章 - 279  trackbacks - 0
<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

潛心看書研究!

常用鏈接

留言簿(19)

隨筆分類(81)

文章分類(89)

相冊(cè)

ACM OJ

My friends

搜索

  •  

積分與排名

  • 積分 - 220984
  • 排名 - 118

最新評(píng)論

閱讀排行榜

評(píng)論排行榜

Antenna Placement
Time Limit:1000MS? Memory Limit:65536K
Total Submit:380 Accepted:125

Description
The Global Aerial Research Centre has been allotted the task of building the fifth generation of mobile phone nets in Sweden. The most striking reason why they got the job, is their discovery of a new, highly noise resistant, antenna. It is called 4DAir, and comes in four types. Each type can only transmit and receive signals in a direction aligned with a (slightly skewed) latitudinal and longitudinal grid, because of the interacting electromagnetic field of the earth. The four types correspond to antennas operating in the directions north, west, south, and east, respectively. Below is an example picture of places of interest, depicted by twelve small rings, and nine 4DAir antennas depicted by ellipses covering them.

Obviously, it is desirable to use as few antennas as possible, but still provide coverage for each place of interest. We model the problem as follows: Let A be a rectangular matrix describing the surface of Sweden, where an entry of A either is a point of interest, which must be covered by at least one antenna, or empty space. Antennas can only be positioned at an entry in A. When an antenna is placed at row r and column c, this entry is considered covered, but also one of the neighbouring entries (c+1,r),(c,r+1),(c-1,r), or (c,r-1), is covered depending on the type chosen for this particular antenna. What is the least number of antennas for which there exists a placement in A such that all points of interest are covered?

Input
On the first row of input is a single positive integer n, specifying the number of scenarios that follow. Each scenario begins with a row containing two positive integers h and w, with 1 <= h <= 40 and 0 < w <= 10. Thereafter is a matrix presented, describing the points of interest in Sweden in the form of h lines, each containing w characters from the set ['*','o']. A '*'-character symbolises a point of interest, whereas a 'o'-character represents open space.

Output
For each scenario, output the minimum number of antennas necessary to cover all '*'-entries in the scenario's matrix, on a row of its own.

Sample Input

2
7 9
ooo**oooo
**oo*ooo*
o*oo**o**
ooooooooo
*******oo
o*o*oo*oo
*******oo
10 1
*
*
*
o
*
*
*
*
*
*

Sample Output

17
5

Source
Svenskt M?sterskap i Programmering/Norgesmesterskapet 2001

myCode:

#include? < iostream >
using ? namespace ?std;

const ? int ?INF? = ? 1 ? << ? 28 ;

int ?n,?r,?c;
int ?e[ 11 ]? = ? { 1 ,? 2 ,? 4 ,? 8 ,? 16 ,? 32 ,? 64 ,? 128 ,? 256 ,? 512 ,? 1024 } ;
char ?m[ 50 ][ 20 ];
int ?d[ 50 ][ 1024 ];
int ?b[ 20 ];
int ?cc[ 20 ];
int ?ss;

void ?Try( int ?x,? int ?s)
{
????
if ?(x? >= ?c)? {
????????
int ?k? = ? 0 ;
????????
for ?( int ?i = 0 ;?i < c;?i ++ )? {
????????????k?
+= ?b[i]? * ?e[i];
????????}

????????
if ?(d[ 0 ][k]? == ? - 1 ? || ?d[ 0 ][k]? > ?s)
????????????d[
0 ][k]? = ?s;
????????
return ?;
????}

????
if ?(m[ 0 ][x]? == ? ' o ' )? {
????????Try(x
+ 1 ,?s);
????}
? else ? if ?(m[ 0 ][x]? == ? ' * ' )? {
????????
int ?t1? = ?b[x],?t2? = ?b[x + 1 ],?t3? = ?s;
????????b[x]?
= ? 1 ;?b[x + 1 ]? = ? 1 ;?s? += ? 1 ;
????????Try(x
+ 2 ,?s);
????????b[x]?
= ?t1;?b[x + 1 ]? = ?t2;?s? = ?t3;
????????
if ?(r? != ? 1 ? || ?m[ 0 ][x]? == ? ' o ' )?Try(x + 1 ,?s);
????}
??
}


void ?DFS( int ?i,? int ?x,? int ?s)
{
????
if ?(x? >= ?c)? {
????????
int ?k? = ? 0 ;
????????
for ?( int ?j = 0 ;?j < c;?j ++ )? {
????????????k?
+= ?cc[j]? * ?e[j];
????????}

????????
if ?(d[i][k]? == ? - 1 ? || ?d[i][k]? > ?ss? + ?s)
????????????d[i][k]?
= ?ss? + ?s;
????????
return ?;
????}

????
if ?(b[x]? == ? 0 )? {
????????
if ?(m[i - 1 ][x]? == ? ' * ' )? {
????????????cc[x]?
= ? 1 ;?s? += ? 1 ;
????????????DFS(i,?x
+ 1 ,?s);
????????}
? else ? {
????????????
if ?(m[i][x]? == ? ' * ' )? {
????????????????
int ?t1? = ?cc[x],?t2? = ?cc[x + 1 ],?t3? = ?s;
????????????????cc[x]?
= ? 1 ;??cc[x + 1 ]? = ? 1 ;?s? += ? 1 ;
????????????????
if ?(b[x + 1 ]? == ? 0 ? && ?m[i - 1 ][x + 1 ]? == ? ' * ' )
????????????????????s?
+= ? 1 ;
????????????????DFS(i,?x
+ 2 ,?s);
????????????????cc[x]?
= ?t1;?cc[x + 1 ]? = ?t2;?s? = ?t3;
????????????????
if ?(i? != ?r - 1 ? || ?m[i][x]? == ? ' o ' )?DFS(i,?x + 1 ,?s);
????????????}
? else ? if ?(m[i][x]? == ? ' o ' )? {
????????????????DFS(i,?x
+ 1 ,?s);
????????????}

????????}

????}
? else ? {
????????????
if ?(m[i][x]? == ? ' * ' )? {
????????????????
int ?t1? = ?cc[x],?t2? = ?cc[x + 1 ],?t3? = ?s;
????????????????cc[x]?
= ? 1 ;??cc[x + 1 ]? = ? 1 ;?s? += ? 1 ;
????????????????
if ?(b[x + 1 ]? == ? 0 ? && ?m[i - 1 ][x + 1 ]? == ? ' * ' )
????????????????????s?
+= ? 1 ;
????????????????DFS(i,?x
+ 2 ,?s);
????????????????cc[x]?
= ?t1;?cc[x + 1 ]? = ?t2;?s? = ?t3;
????????????????
if ?(i? != ?r - 1 ? || ?m[i][x]? == ? ' o ' )?DFS(i,?x + 1 ,?s);
????????????}
? else ? if ?(m[i][x]? == ? ' o ' )? {
????????????????DFS(i,?x
+ 1 ,?s);
????????????}
??????
????}

}


void ?init()
{
????memset(d[
0 ],? - 1 ,? sizeof (d[ 0 ]));
????memset(b,?
0 ,? sizeof (b));
????Try(
0 ,? 0 );
}


void ?Solve()?
{
????
int ?i,?j,?k;
????init();
????
for ?(i = 0 ;?i < r - 1 ;?i ++ )? {
????????memset(d[i
+ 1 ],? - 1 ,? sizeof (d[i + 1 ]));
????????
for ?(k = 0 ;?k < e[c];?k ++ )? {
????????????
if ?(d[i][k]? != ? - 1 )? {
????????????????
int ?t? = ?k,?j? = ? 0 ,?kk? = ? 0 ;
????????????????memset(b,?
0 ,? sizeof (b));
????????????????memset(cc,?
0 ,? sizeof (cc));
????????????????
while ?(t? != ? 0 )? {
????????????????????b[j
++ ]? = ?t? % ? 2 ;
????????????????????t?
/= ? 2 ;
????????????????}

????????????????ss?
= ?d[i][k];
????????????????DFS(i
+ 1 ,? 0 ,? 0 );
????????????}

????????}

????}

????
int ?ans? = ?INF;
????
for ?(k = 0 ;?k < e[c];?k ++ )? {
????????
if ?(d[r - 1 ][k]? != ? - 1 ? && ?d[r - 1 ][k]? < ?ans)? {
????????????ans?
= ?d[r - 1 ][k];
????????}

????}

????cout?
<< ?ans? << ?endl;
}


int ?main()
{?
????cin?
>> ?n;
????
while ?(n -- ? != ? 0 )? {
????????cin?
>> ?r? >> ?c;
????????
for ?( int ?i = 0 ;?i < r;?i ++ )?cin? >> ?m[i];
????????Solve();
????}

????system(
" pause " );
????
return ? 0 ;
}


ghost_wei大牛的code,? 放出來(lái)供大家學(xué)習(xí),? 用了滾動(dòng)數(shù)組優(yōu)化, 而且位運(yùn)算用得出神入化:)
#include<iostream.h>
#include?
<fstream.h>
const?int?k2[11]={1,2,4,8,16,32,64,128,256,512,1024};
int?n,m,c[2][1024];
char?d[40][10];
inline?
void?min(int?&i,int?j)
{
????
if?(i>j)?i=j;
}

void?work()
{
????
int?i,j,km,k,e7,e8,l,t,ans;
????km
=k2[m];
????
for?(i=0;i<km;i++)?c[0][i]=100000;
????c[
0][0]=0;
????e7
=0;?e8=1;
????
for?(i=0;i<n;i++)
????
{
????????
for?(j=0;j<km;j++)?c[e8][j]=100000;
????????
for?(j=1;j<m;j++)
????????????
if?(d[i][j]=='*')
????????????????
for?(k=0;k<km;k++)
????????????????????min(c[e7][k
|k2[j]|k2[j-1]],c[e7][k]+1);
????????
for?(k=0;k<km;k++)
????????
{
????????????l
=0;?t=0;
????????????
for?(j=0;j<m;j++)?
????????????????
if?(!(k&k2[j])&&d[i][j]=='*')
????????????????
{
????????????????????l
+=k2[j];
????????????????????t
++;
????????????????}

????????????min(c[e8][l],c[e7][k]
+t);
????????}

????????e7
=e7^1;?e8=e8^1;
????}

????ans
=100000;
????
for?(k=0;k<km;k++)
????????min(ans,c[e7][k]);
????cout
<<ans<<endl;
}

int?main()
{
????
int?tc,cas,i,j;
????cin
>>tc;
????
for?(cas=1;cas<=tc;cas++)
????
{
????????cin
>>n>>m;
????????
for?(i=0;i<n;i++)
????????????
for(j=0;j<m;j++)
????????????????cin
>>d[i][j];
????????work();
????}

????
return?0;
}

posted on 2006-10-18 17:29 閱讀(2158) 評(píng)論(4)  編輯 收藏 引用 所屬分類: ACM題目

FeedBack:
# re: 狀態(tài)壓縮DP, pku3020[未登錄](méi) 2007-04-30 11:16 Leon
Ghost的算法真是精辟,只是狀態(tài)數(shù)組定義的空間可能會(huì)不夠,代碼的line 30  回復(fù)  更多評(píng)論
  
# re: 狀態(tài)壓縮DP, pku3020 2007-06-30 10:35 姜雨生
真是太好了
以后多向你請(qǐng)教  回復(fù)  更多評(píng)論
  
# re: 狀態(tài)壓縮DP, pku3020[未登錄](méi) 2008-07-02 08:22 菜鳥
大牛解釋一下這一段吧:
for (i=0;i<n;i++)
{
for (j=0;j<km;j++) c[e8][j]=100000;
for (j=1;j<m;j++)
if (d[i][j]=='*')
for (k=0;k<km;k++)
min(c[e7][k|k2[j]|k2[j-1]],c[e7][k]+1);
for (k=0;k<km;k++)
{
l=0; t=0;
for (j=0;j<m;j++)
if (!(k&k2[j])&&d[i][j]=='*')
{
l+=k2[j];
t++;
}
min(c[e8][l],c[e7][k]+t);
}
e7=e7^1; e8=e8^1;
}
  回復(fù)  更多評(píng)論
  
# re: 狀態(tài)壓縮DP, pku3020 2008-08-04 22:56 ecnu
二分匹配做的。。關(guān)鍵是狀態(tài)壓縮不會(huì)。5555...  回復(fù)  更多評(píng)論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
      <noscript id="pjuwb"></noscript>
            <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
              <dd id="pjuwb"></dd>
              <abbr id="pjuwb"></abbr>
              欧美亚州一区二区三区| 亚洲影院色在线观看免费| 欧美成人视屏| 亚洲精品国产精品乱码不99按摩| 亚洲美女毛片| 久久riav二区三区| 亚洲国产成人在线视频| 亚洲一卡二卡三卡四卡五卡| 久久亚洲国产精品一区二区 | 亚洲一区二区三区涩| 久久av红桃一区二区小说| 亚洲影院免费观看| 国产日韩一区二区| 亚洲性图久久| 这里只有精品电影| 欧美国产激情二区三区| 国产一区二区三区最好精华液| 中文欧美在线视频| 亚洲第一色中文字幕| 欧美激情免费在线| 国内精品视频666| 欧美一级精品大片| 亚洲精品日韩久久| 另类激情亚洲| 伊人色综合久久天天五月婷| 久久不见久久见免费视频1| 欧美一区二区三区精品电影| 国产精品人成在线观看免费 | 欧美日本亚洲韩国国产| 国语自产在线不卡| 久久久久久久91| 午夜久久久久久| 国产精品青草久久久久福利99| 久久频这里精品99香蕉| 亚洲欧美成人网| 国产精品视频区| 亚洲电影下载| 国产伦精品一区二区三区视频孕妇| 一区二区三区视频在线| 99精品欧美一区| 欧美三级视频在线播放| 国产精品99久久久久久久女警 | 久久国产直播| 国模套图日韩精品一区二区| 亚洲国产一区二区视频 | 亚洲毛片av在线| 黑丝一区二区| 亚洲一区亚洲| 亚洲图片欧美一区| 免费视频亚洲| 一本不卡影院| 亚洲视频每日更新| 最新中文字幕亚洲| 亚洲精品美女久久7777777| 狠狠爱www人成狠狠爱综合网| 日韩视频在线一区二区三区| 国产美女精品视频| 日韩一级在线| 亚洲精品一二三| 亚洲亚洲精品在线观看| 一区二区三区国产在线| 久久综合国产精品| 久久这里只有| 欧美日韩喷水| 久久视频一区| 国产在线不卡| 欧美在线视屏| 99xxxx成人网| 欧美一级免费视频| 午夜综合激情| 国产精品伦子伦免费视频| 久久久一区二区| 国产亚洲综合在线| 欧美亚洲系列| 久久阴道视频| 亚洲丰满在线| 亚洲自拍偷拍网址| 午夜免费在线观看精品视频| 欧美aⅴ99久久黑人专区| 欧美大香线蕉线伊人久久国产精品| 狠狠色狠狠色综合日日小说| 久久久久久久久久久久久久一区 | 一区二区三区久久精品| 欧美美女日韩| 在线亚洲国产精品网站| 亚洲欧美国产精品专区久久| 久久视频在线看| 欧美大片一区二区| 亚洲黄色一区二区三区| 亚洲欧美高清| 久久久久久久久久看片| 在线欧美三区| 欧美影院视频| 美腿丝袜亚洲色图| 国产精品中文在线| 久久精品av麻豆的观看方式 | 亚洲深夜福利视频| 国产精品久久久久久久久久直播| 亚洲欧美国产三级| 美日韩精品免费| 最近看过的日韩成人| 欧美日韩视频第一区| 午夜精品视频在线观看| 美日韩精品免费观看视频| 亚洲日本中文字幕| 国产精品日日摸夜夜摸av| 久久久成人网| 久久综合一区二区三区| 国产日韩欧美在线视频观看| 久久人人看视频| 一区二区三区国产盗摄| 亚洲线精品一区二区三区八戒| 国产欧美一区二区三区另类精品| 亚洲一级黄色片| 欧美二区在线看| 欧美一级在线视频| 欧美日韩高清在线观看| 欧美激情1区2区3区| 亚洲丁香婷深爱综合| 欧美日韩成人| 久久亚洲捆绑美女| 亚洲专区免费| 亚洲激情视频| 一区二区三区视频在线播放| 国产一区二区三区高清播放| 欧美日韩国产成人精品| 久久精品国产精品亚洲| 亚洲一区精品电影| 亚洲精品免费在线观看| 玖玖精品视频| 欧美亚洲视频一区二区| 一区二区三区欧美在线| 亚洲国产一区二区a毛片| 国产欧美日韩视频一区二区| 欧美手机在线| 欧美伦理视频网站| 欧美1区2区视频| 久久久精品日韩欧美| 亚洲一区二区影院| 中文网丁香综合网| 亚洲美女精品成人在线视频| 亚洲第一黄色| 亚洲夫妻自拍| 亚洲电影在线观看| 久久视频一区| 六十路精品视频| 久久综合一区二区三区| 久久一区二区三区国产精品 | 久久久久九九视频| 亚洲欧美精品在线| 亚洲一区久久久| 狠狠操狠狠色综合网| 国产视频欧美| 国产一区二区三区直播精品电影 | 尤物yw午夜国产精品视频明星| 国产亚洲欧美在线| 国产亚洲精品一区二555| 国产毛片一区| 韩日成人在线| 亚洲成人直播| 亚洲精品一区二区三区在线观看| 91久久精品国产91久久性色| 亚洲欧洲在线看| 一本色道久久综合亚洲二区三区 | 亚洲一区二区三区三| 亚洲午夜激情网站| 亚洲欧美www| 久久免费精品日本久久中文字幕| 久久夜色精品国产欧美乱| 免费黄网站欧美| 亚洲人成在线观看| 99精品国产在热久久下载| 亚洲——在线| 久久中文字幕导航| 欧美日韩国产精品一区| 国产伦精品一区| 最新亚洲一区| 亚洲欧美日本国产专区一区| 久久久亚洲影院你懂的| 亚洲电影免费观看高清完整版| 99伊人成综合| 久久成人免费网| 欧美人体xx| 国产在线国偷精品产拍免费yy| 在线成人www免费观看视频| 99在线精品视频| 久久精品视频在线播放| 午夜激情久久久| 欧美成人黄色小视频| 久久欧美中文字幕| 亚洲精品国久久99热| 欧美亚洲色图校园春色| 欧美大尺度在线观看| 蜜桃精品一区二区三区| 久热精品视频在线| 欧美午夜理伦三级在线观看| 在线看国产日韩| 午夜免费日韩视频| 亚洲精品在线二区| 久久久在线视频|