hdu4109拓扑
来源:互联网 发布:听音识谱软件手机 编辑:程序博客网 时间:2024/06/05 20:07
http://acm.hdu.edu.cn/showproblem.php?pid=4109
Instrction Arrangement
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1320 Accepted Submission(s): 558
Problem Description
Ali has taken the Computer Organization and Architecture course this term. He learned that there may be dependence between instructions, like WAR (write after read), WAW, RAW.
If the distance between two instructions is less than the Safe Distance, it will result in hazard, which may cause wrong result. So we need to design special circuit to eliminate hazard. However the most simple way to solve this problem is to add bubbles (useless operation), which means wasting time to ensure that the distance between two instructions is not smaller than the Safe Distance.
The definition of the distance between two instructions is the difference between their beginning times.
Now we have many instructions, and we know the dependent relations and Safe Distances between instructions. We also have a very strong CPU with infinite number of cores, so you can run as many instructions as you want simultaneity, and the CPU is so fast that it just cost 1ns to finish any instruction.
Your job is to rearrange the instructions so that the CPU can finish all the instructions using minimum time.
If the distance between two instructions is less than the Safe Distance, it will result in hazard, which may cause wrong result. So we need to design special circuit to eliminate hazard. However the most simple way to solve this problem is to add bubbles (useless operation), which means wasting time to ensure that the distance between two instructions is not smaller than the Safe Distance.
The definition of the distance between two instructions is the difference between their beginning times.
Now we have many instructions, and we know the dependent relations and Safe Distances between instructions. We also have a very strong CPU with infinite number of cores, so you can run as many instructions as you want simultaneity, and the CPU is so fast that it just cost 1ns to finish any instruction.
Your job is to rearrange the instructions so that the CPU can finish all the instructions using minimum time.
Input
The input consists several testcases.
The first line has two integers N, M (N <= 1000, M <= 10000), means that there are N instructions and M dependent relations.
The following M lines, each contains three integers X, Y , Z, means the Safe Distance between X and Y is Z, and Y should run after X. The instructions are numbered from 0 to N - 1.
The first line has two integers N, M (N <= 1000, M <= 10000), means that there are N instructions and M dependent relations.
The following M lines, each contains three integers X, Y , Z, means the Safe Distance between X and Y is Z, and Y should run after X. The instructions are numbered from 0 to N - 1.
Output
Print one integer, the minimum time the CPU needs to run.
Sample Input
5 21 2 13 4 1
Sample Output
2
#include <iostream>#include <string.h>#include <queue>#include <stdio.h>using namespace std;const int M=1005;struct Node{ int v,w,next;}edge[M*10];int n,m,cnt;int ind[M],ans[M*10],frist[M*10];void inti(){ memset(ans,0,sizeof(ans)); memset(ind,0,sizeof(ind)); memset(frist,-1,sizeof(frist));}int max(int a,int b){ if(a>b) return a; else return b;}void uino(int u,int v,int w)///邻接表{ edge[cnt].v=v; edge[cnt].w=w; edge[cnt].next=frist[u]; frist[u]=cnt++;}void read_case(){ int a,b,w; for(int i=0;i<m;i++ ) { scanf("%d%d%d",&a,&b,&w); uino(a,b,w); ind[b]++; }}void solve(){ queue<int>q; for(int i=0;i<n;i++) { if(!ind[i]) { q.push(i); ans[i]=1; } } while(!q.empty()) { int t=q.front(); q.pop(); for(int e=frist[t];e!=-1;e=edge[e].next)///!!! { int v=edge[e].v; int ww=edge[e].w; if(--ind[v]==0) q.push(v); if(ans[v]<ans[t]+ww) ans[v]=ans[t]+ww;///!!! } }}int main(){ while(~scanf("%d%d",&n,&m)) { inti(); cnt=0; read_case(); solve(); int Max=0; for(int i=0;i<n;i++) Max=max(ans[i],Max); printf("%d\n",Max); } return 0;}
0 0
- hdu4109拓扑
- hdu4109拓扑Instrction Arrangement
- hdu4109(拓扑排序,dp)
- HDU4109 Instrction Arrangement 拓扑排序 关键路径
- hdu4109
- HDU4109 Instrction Arrangement 拓扑排序求关键路径
- HDU4109 Instrction Arrangement【差分约束】【拓扑排序】
- HDU4109 Instrction Arrangement @Z
- HDU4109——Instrction Arrangement(关键路径)
- 拓扑
- 拓扑
- 拓扑
- 拓扑
- 拓扑排序
- 网络拓扑
- 拓扑结构图
- 拓扑排序
- 拓扑排序
- 多字节字符集下CString转char*
- 所谓的位置问题
- JavaScript按照MVC模式制作自定义控件
- 北京地区医院HIS系统供应商统计(最新版)
- android 加载数据或提交数据时显示转圈的提示页面
- hdu4109拓扑
- JS 实现跨页事件响应
- 装饰模式
- c语言-union联合体的使用
- MDS setting for testing PDef business components using AM tester
- 最长无重复字符子串
- springmvc 中 Instantiation of bean failed实例化Bean失败错误
- 如何成为全栈工程师?
- win7中mysql5.7.7的配置部署