Advanced Prog. Lab File
Advanced Prog. Lab File
Programming
Lab
File
N.S.I.T
Submitted By:
Jaideep Kumar
738/IT/13
INDEX
S.No
.
Problem
Date
Sign
//NODE
q.pop();
if(dist[v]<d) continue;
for(int i=0 ;i<adj[v].size();i++)
{int a=adj[v][i].first ;
int b=adj[v][i].second;
if( dist[a] > dist[v] + b ){
//
NODE
//
DIST
OUTPUT:
if (magicMat[i][j])
{ i--;
continue; }
else
magicMat[i][j] = num++;
i--;
j--;
}cout<<"The Magic Matrix for n="<<n<<":\nSum of each row or column
"<<(n*(n*n+1)/2)<<endl;
for(i=0;i<n; i++)
{ for(j=0; j<n; j++)
cout<<magicMat[i][j]<<" ";
cout<<endl;
}}int main()
{int n ;
cin>>n;
generateMat (n);
return 0;
}
OUTPUT:
ord[i][j]=k;
}}}}return m[1][n-1];
}void print(int i,int j){
if(i==j){
cout<<"m"<<1;
return;}
cout<<"(";
print(i,ord[i][j]);
print(ord[i][j]+1,j);
cout<<")";
}int main()
{int arr[100],n;
cout<<"enter no. of matrices";
cin>>n;
for(int i=0;i<=n;i++)
{cin>>arr[i];}
cout<<"Minimum number of multiplications is "<<MatrixChainOrder(arr, n);
getchar();
return 0;
}
OUTPUT:
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
} i=n;j=m;
char *str=(char *)malloc ((len+1)*sizeof(char));
int g=dp[n][m];
str[g--]='\0';
while(i && j)
{if(x[i-1]==y[j-1])
{str[g--]=x[i-1];
i--;j--;
}else if(dp[i-1][j]>dp[i][j-1])
i--;
else j--;}
return str;}
int main()
{char x[len],y[len];
int i,j,n;
cout<<"enter string \n";
cin>>n;
cin>>x>>y;
char *str=lcs(x,y);
for(i=3;i<=n;i++)
{cin>>y;
str=lcs(str,y);}
cout<<str;
return 0;
}
OUTPUT:
//items, weight;
int weight[100],profit[100];
int dp[100][100];
cout<<"enter no. of items\n";
cin>>n;
cout<<"enter total capacity of knapsack\n";
cin>>m;
for(int i=1;i<=n;i++)
cin>>weight[i];
for(int i=1;i<=n;i++)
cin>>profit[i];
dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){dp[i][j]=0;
if(weight[i]<=j)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i]]+profit[i]);
}}cout<<"Profit is "<<dp[n][m];}
OUTPUT:
tot_v += v[maxi];
if (cur_w < 0)
{ tot_v -= v[maxi];
tot_v += (1 + (float)cur_w/w[maxi]) * v[maxi];
}} cout<<"total profit is"<< tot_v;}
int main()
{int n,k;
cout<<"Enter no. of items\n";
cin>>n;
cout<<"Enter total capacity of Knapsack\n";
cin>>k;
int weight[100],value[100];
int i;
for(i=0;i<n;i++)
{cin>>weight[i];
}for(i=0;i<n;i++)
{cin>>value[i];
}knapsack(weight,value,k,n);
return 0;
}
OUTPUT: