http://poj.org/problem?id=3592

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define maxn 300000
using namespace std; const int inf=-<<;
int e,head[maxn],belong[maxn],stack1[maxn],top,dfn[maxn],low[maxn],bcc_clock,bcnt,n,m,num1[][],num,gg[maxn],point[maxn],cc[maxn],ee,head1[maxn],dis[maxn],cnt[maxn],temp;
bool vis[maxn],visi[maxn];
int dir[][]= {{,},{,}};
struct node
{
int u,v,next;
} p[maxn];
struct node1
{
int u,v,w,next;
} pp[maxn];
char g[][]; void add(int u,int v)
{
p[e].u=u;
p[e].v=v;
p[e].next=head[u];
head[u]=e++;
} void addnode(int u,int v,int w)
{
pp[ee].v=v;
pp[ee].u=u;
pp[ee].w=w;
pp[ee].next=head1[u];
head1[u]=ee++;
} void tarjan(int u)
{
vis[u]=true;
dfn[u]=low[u]=++bcc_clock;
stack1[++top]=u;
for(int i=head[u]; i!=-; i=p[i].next)
{
int v=p[i].v;
if(!dfn[v])
{
tarjan(v);
low[u]=min(low[u],low[v]);
}
else if(vis[v])
low[u]=min(low[u],dfn[v]);
}
if(dfn[u]==low[u])
{
bcnt++;
int j;
do
{
j=stack1[top--];
vis[j]=false;
belong[j]=bcnt;
}
while(j!=u);
}
} void init()
{ memset(dfn,,sizeof(dfn));
memset(low,,sizeof(low));
memset(belong,,sizeof(belong));
memset(cc,,sizeof(cc));
memset(vis,false,sizeof(vis));
} void del()
{
init();
for(int i=; i<n*m; i++)
{
if(!dfn[i])
{
tarjan(i);
}
}
} bool ralex(int u,int v,int c)
{
if(dis[v]<dis[u]+c)
{
dis[v]=dis[u]+c;
return true;
}
return false;
} bool spfa(int src)
{
memset(visi,false,sizeof(visi));
memset(cnt,,sizeof(cnt));
visi[src]=true;
for(int i=; i<=bcnt; i++)
{
dis[i]=inf;
}
queue<int>q;
q.push(src);
dis[src]=;
while(!q.empty())
{
int u=q.front();
q.pop();
visi[u]=false;
for(int i=head1[u]; i!=-; i=pp[i].next)
{
if(ralex(u,pp[i].v,pp[i].w)&&!visi[pp[i].v])
{
if((++cnt[pp[i].v])>n*m) return false;
q.push(pp[i].v);
visi[pp[i].v]=true;
}
}
}
temp=;
for(int i=; i<bcnt+; i++)
{
temp=max(temp,dis[i]);
}
return true;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
num=;
int cn=;
memset(head1,-,sizeof(head1));
memset(head,-,sizeof(head));
e=,top=,bcnt=,bcc_clock=,ee=;
getchar();
for(int i=; i<n; i++)
{
scanf("%s",g[i]);
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
int k=i*m+j;
if(g[i][j]=='#')
{
gg[k]=-;
continue;
}
else
{
if(g[i][j]=='*')
{
point[cn++]=k;
gg[k]=;
}
else if(g[i][j]>=''&&g[i][j]<='')
{
gg[k]=g[i][j]-'';
}
for(int c=; c<; c++)
{
int xx=i+dir[c][];
int yy=j+dir[c][];
if(xx<n&&yy<m)
{
if(g[xx][yy]!='#')
{
add(k,xx*m+yy);
}
}
} }
}
}
for(int i=; i<cn; i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(g[x][y]!='#')
{
add(point[i],x*m+y);
}
}
del();
for(int i=; i<n*m; i++)
{
cc[belong[i]]+=gg[i];
}
addnode(,belong[],cc[belong[]]);
for(int i=; i<n*m; i++)
{
for(int j=head[i]; j!=-; j=p[j].next)
{
int v=p[j].v;
if(belong[i]!=belong[v])
{
addnode(belong[i],belong[v],cc[belong[v]]);
}
}
}
spfa();
printf("%d\n",temp);
}
return ;
}

poj 3592 Instantaneous Transference的更多相关文章

  1. POJ 3592 Instantaneous Transference(强连通+DP)

    POJ 3592 Instantaneous Transference 题目链接 题意:一个图.能往右和下走,然后有*能够传送到一个位置.'#'不能走.走过一个点能够获得该点上面的数字值,问最大能获得 ...

  2. poj 3592 Instantaneous Transference 【SCC +缩点 + SPFA】

    Instantaneous Transference Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6204   Accep ...

  3. POJ 3592 Instantaneous Transference(强联通分量 Tarjan)

    http://poj.org/problem?id=3592 题意 :给你一个n*m的矩阵,每个位置上都有一个字符,如果是数字代表这个地方有该数量的金矿,如果是*代表这个地方有传送带并且没有金矿,可以 ...

  4. poj 3592 Instantaneous Transference 缩点+最长路

    题目链接 给一个n*m的图, 从0, 0这个点开始走,只能向右和向下. 图中有的格子有值, 求能获得的最大值. 其中有些格子可以传送到另外的格子, 有些格子不可以走. 将图中的每一个格子都看成一个点, ...

  5. POJ3592 Instantaneous Transference tarjan +spfa

    链接:http://poj.org/problem?id=3592 题意:题目大意:给定一个矩阵,西南角为出发点,每个单位都有一订价值的金矿(#默示岩石,不成达,*默示时佛门,可以达到指定单位),队# ...

  6. Instantaneous Transference(强连通分量及其缩点)

    http://poj.org/problem?id=3592 题意:给出一个n*m的矩阵,左上角代表起始点,每个格子都有一定价值的金矿,其中‘#’代表岩石不可达,‘*’代表时空门可以到达指定格子,求出 ...

  7. POJ3592 Instantaneous Transference 强连通+最长路

    题目链接: id=3592">poj3592 题意: 给出一幅n X m的二维地图,每一个格子可能是矿区,障碍,或者传送点 用不同的字符表示: 有一辆矿车从地图的左上角(0,0)出发, ...

  8. POJ3592 Instantaneous Transference题解

    题意: 给一个矩形,矩形中某些点有一定数量的矿石,有些点为传送点,有些点为障碍.你驾驶采矿车(ore-miner truck,我也不知道是什么),从左上角出发,采尽量多的矿石,矿石不可再生.不能往左边 ...

  9. poj 3592 缩点+SPFA

    题意:给出一个矩阵,其中#代表墙,不可走,0-9代表权值,*代表可以选择传送.求从0,0点开始出发能获得最大权值. 思路:因为*的出现会有环的情况,先建图连边,将环进行Tarjan缩点,之后再从0,0 ...

随机推荐

  1. AE 3D摄像机工作原理

    看了AE教程的3D可视化音频和序列法导入三维模型之后对于视频解析3D是有了更深的认识.很感谢AE在CS6之后加入了3D摄像机跟踪器的功能.它是通过摄像机跟踪反求来得到影片中的平面特征点.然后由用户指定 ...

  2. Drawer_layout 关闭滑动视图

    在android抽屉Drawer_layout开发中,我需要关闭滑动的试图 找到了这个方法 mDrawer_layout.setDrawerLockMode(DrawerLayout.LOCK_MOD ...

  3. Android_硬编码设置TextView字体大小

    使用如下代码时,发现字号不会变大,反而会变小:size = (int) mText.getTextSize() + 1;mText.setTextSize(size);后来发现getTextSize返 ...

  4. [PWA] 9. Service worker registerion && service work's props, methods and listeners

    In some rare cases, you need to ask user to refresh the browsser to update the version. Maybe becaus ...

  5. yii 载入css or js

    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . "/js/TableView.js&q ...

  6. 1_Linux_目录简介

    1. Linux中所以内容以文件形式保存,包括硬件,所以在用命令行配置文件时,该配置仅仅是临时生效.   2. Linux不靠扩展名区分类型,而是靠文件权限.之所以有扩展名是为了便于管理. .rpm二 ...

  7. 移动Web开发技巧

    META相关 1. 添加到主屏后的标题(IOS) <meta name="apple-mobile-web-app-title" content="标题" ...

  8. Dhroid框架笔记(IOC、EventBus)

    dhroid 目前包含了6大组件供大家使用1.Ioc容器: (用过spring的都知道)视图注入,对象注入,接口注入,解决类依赖关系2.Eventbus: android平台事件总线框架,独创延时事件 ...

  9. Web字体工具整理,网页图标字体以及使用方法整理

    常用网站app logo 下载: http://www.iconfont.cn/collections/show/268?spm=a313x.7781069.0.0.nDYawz 1.Web字体免费生 ...

  10. 无法在web服务器上启动调试。调试失败,因为没有启用集成windows身份验证

    ----注意:以管理员身份运行VS C#中ASP.NET Web应用程序编译时的错误:无法在web服务器上启动调试.调试失败,因为没有启用集成windows身份验证. 解决:打开IIS,在IIS里查看 ...