Pagini recente » Cod sursa (job #2956836) | Cod sursa (job #1695846) | Cod sursa (job #2214200) | Cod sursa (job #1720340) | Cod sursa (job #724366)
Cod sursa(job #724366)
#include<fstream>
#include<algorithm>
using namespace std;
pair<int,int> a[220];
int b[220][220];
int n;
int div(int st,int dr,int tata)
{
int i;
if(b[st][dr])
return b[st][dr];
if(st>dr)
return 0;
b[st][dr]=1<<30;
for(i=st;i<=dr;i++)
{
b[st][dr]=min(max(div(st,i-1,i),div(i+1,dr,i))+a[i].second+a[tata].second+abs(a[tata].first-a[i].first),b[st][dr]);
}
return b[st][dr];
}
int main()
{int i;
ifstream f("wanted.in");
ofstream g("wanted.out");
f>>n;
for(i=1;i<=n;i++)
f>>a[i].first>>a[i].second;
sort(a+1,a+n+1);
g<<div(1,n,0);
f.close();
g.close();
}