PHIDIAS - Phidias - SPOJ Solution C++

  Problem Link : PHIDIAS 


👉 Hint : edit please

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int w,h;
		cin>>w>>h;
		int n;
		cin>>n;
		vector<pair<int,int> >v;
		for(int i=0;i<n;i++)
		{
			int w1,h1;
			cin>>w1>>h1;
			v.push_back(make_pair(h1,w1));
		}
		int dp[h+1][w+1];
	
		for(int i=0;i<=w;i++)
			dp[0][i]=0;
		for(int i=0;i<=h;i++)
			dp[i][0]=0;
		int mini;
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				dp[i][j]=i*j;
				for(int k=0;k<n;k++)
				{
					if(v[k].first<=i && v[k].second<=j)
					{
						mini=min(dp[i-v[k].first][v[k].second]+dp[i][j-v[k].second],dp[v[k].first][j-v[k].second]+dp[i-v[k].first][j]);
						dp[i][j]=min(mini,dp[i][j]);
					}
				}
			}
		}
	
		cout<<dp[h][w]<<endl;
	}
	return 0;
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!