1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NISA [10]
3 years ago
12

There are n tasks to complete. Each task first needs to be preprocessed on a supercomputer and then finished on one of n process

ors. Task i requires pi seconds of preprocessing on the supercomputer followed by fi seconds on some processor to complete. Note that tasks are fed to the supercomputer sequentially but can be executed in parallel on different processors once they have been preprocessed. The process terminates when all tasks have been completed. The duration of the process is the total time until termination. Give an efficient algorithm that determines an ordering of the tasks for the supercomputer that minimizes the duration of the process, as well as the minimum duration.
Computers and Technology
1 answer:
evablogger [386]3 years ago
7 0

Answer:

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()

{

ll i,n,j,s;

cout<<"Enter size of array: ";

cin>>n;

ll a[n];

cout<<"Enter elements of array: ";

s=0;

for(i=0;i<n;i++)

{

cin>>a[i];

s+=a[i];

}

if(s%3!=0)

{

cout<<"No";

return 0;

}

ll dp[n][s/3+1];

for(i=0;i<=s/3;i++)

{

if(i==a[0])

dp[0][i]=1;

else

dp[0][i]=0;

}

for(i=0;i<n;i++)

dp[i][0]=1;

for(i=1;i<n;i++)

for(j=0;j<=s/3;j++)

{

if(j<a[i])

dp[i][j]=dp[i-1][j];

else

dp[i][j]=dp[i-1][j]||dp[i-1][j-a[i]];

}

if(dp[n-1][s/3]==0)

{

cout<<"No";

return 0;

}

ll vis[n];

for(i=0;i<n;i++)

vis[i]=0;

ll curr=s/3;

ll indx=n-1;

ll c=0;

while(indx>0)

{

if(dp[indx][curr]==1&&(curr-a[indx]>=0&&dp[indx-1][curr-a[indx]]==1))//include indx

{

vis[indx]=1;

curr=curr-a[indx];

c++;

}

indx--;

}

if(dp[0][curr]==1){

vis[0]=1;

c++;}

ll b[n-c];

ll k=0;

for(i=0;i<n;i++)

{

if(vis[i]==0)

b[k++]=a[i];

}

ll dp1[k][s/3+1];

for(i=0;i<=s/3;i++)

{

if(i==b[0])

dp1[0][i]=1;

else

dp1[0][i]=0;

}

for(i=0;i<k;i++)

dp1[i][0]=1;

for(i=1;i<k;i++)

for(j=0;j<=s/3;j++)

{

if(j<b[i])

dp1[i][j]=dp1[i-1][j];

else

dp1[i][j]=dp1[i-1][j]||dp1[i-1][j-b[i]];

}

if(dp1[k-1][s/3]==0)

{

cout<<"No";

return 0;

}

else

cout<<"Yes";

}

Explanation:

You might be interested in
The cell address ZZ123 means
mafiozo [28]
The range of cells from zz1 to zz23
7 0
2 years ago
Read 2 more answers
How do I logout of Brainly on mobile? When I went to settings, it had the option to log out but it was grayed out.
poizon [28]
Just delete the app
8 0
3 years ago
Which argument forces a writer to return to and change the input before resolving a “UnicodeError”?
garri49 [273]

Answer:

B

Explanation:

3 0
3 years ago
How to run angular project from github.
sergiy2304 [10]

Answer:

i have no ideaaaaaaaaaaaaaaaaaaaaaa

Explanation:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa kill me

6 0
2 years ago
For our computer club in school, we are making a discord server and seeing who can get the most members. I am making an Anime Se
Gwar [14]

Answer:

misteragua#1874

Explanation:

5 0
2 years ago
Other questions:
  • 14. Which commercial RDBMS product was the first to hit the market and is the biggest?
    15·1 answer
  • Your friend is working on fixing their Homework assignment. They need a lot of help. You know all the bugs in the file, but due
    12·1 answer
  • The utilization of a subset of the performance equation as a performance metric is a pitfall. To illustrate this, assume the fol
    13·1 answer
  • Which of the following are you likely to find between multiple school buildings in a city wide school district?
    9·1 answer
  • Double clicking a word selects the entire word?
    10·1 answer
  • Although some families have more resources than other families, there is always a limited amount of resources that families have
    15·2 answers
  • What is it called to persist in trying to multitask can result in this; the scattering bits of one’s attention among a number of
    9·1 answer
  • What does cmyk stand for?
    5·2 answers
  • write a program that asks the user for a month number and displays the number of days that month has?
    7·2 answers
  • Define a function Output Value() that takes two integer parameters and outputs the sum of all negative integers starting with th
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!