690 - Pipeline Scheduling
Pipeline Scheduling In this problem,a pipeline may have a feedback structure,that is,data paths among function units may have directed loops as shown in the next figure. Example of a feedback pipeline Example of “reservation table” clock 0 1 2 3 4 5 6 In reservation tables, Notice that no special hardware is provided to avoid simultaneous use of the same function unit. Therefore,a task must not be started if it would conflict with any tasks being processed. For instance,with the above reservation table,if two tasks,say task 0 and task 1,were started at clock 0 and clock 1,respectively,a conflict would occur on unit0 at clock 5. This means that you should not start two tasks with single cycle interval. This invalid schedule is depicted in the following process table,which is obtained by overlapping two copies of the reservation table with one being shifted to the right by 1 clock. Example of “conflict” clock 0 1 2 3 4 5 6 7 Your job is to write a program that reports the minimum number of clock cycles in which the given pipeline can process 10 tasks. Input The integer n(< 20) in the first line is the width of the reservation table,or the number of clock cycles that is necessary to perform a single task. The second line represents the usage of unit0,the third line unit1,and so on. xi,j is either Output For each data set,your program should output a line containing an integer number that is the minimum number of clock cycles in which the given pipeline can process 10 tasks. 7 34 Miguel A. Revilla 我有话说: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=5;
const int M=100;
int n,c,ans,w[N],jump[M];
bool judge(int* s,int k)
{
for(int i=0;i<N;i++)
if((s[i]>>k)&w[i])return false;//如果和前一个冲突
return true;
}
void Init()
{
char s[M];
c=0;
ans=10*n;
memset(w,0,sizeof(w));//清零
for(int i=0;i<N;i++)
{
scanf("%s",s);
for(int j=0;j<n;j++)
{
if(s[j]=='X')
w[i]|=(1<<j);
}
}
for(int i=0;i<=n;i++)
{
if(judge(w,i))jump[c++]=i;//剪枝1:事先枚举能够放的位置。当然是在最理想的状态下只有一个未完进程。
}
}
void dfs(int* s,int d,int sum)
{
if(sum+(10-d)*jump[0]>ans)return;//剪枝2:如果目前最优情况比ans大直接剪枝
if(d==10){
ans=min(sum,ans);
return;
}
for(int i=0;i<c;i++)
{
if(judge(s,jump[i])){
int p[N];
for(int j=0;j<N;j++)
p[j]=(s[j]>>jump[i])^w[j];
dfs(p,d+1,sum+jump[i]);
}
}
}
int main()
{
while(scanf("%d",&n)==1&&n)
{
Init();
dfs(w,1,n);
printf("%dn",ans);
}
return 0;
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |