当前位置:网站首页>1069. Division of convex polygons (thinking, interval DP)
1069. Division of convex polygons (thinking, interval DP)
2022-07-02 01:45:00 【seez】

Limiting conditions :
- It is divided into N-2 Triangles
- Disjoint
analysis :

Because a triangle needs three vertices , We can enumerate three vertices first , Then observe the nature
Pictured , When we show i,j,k Three vertices , At present, it can be divided into three sets
- Polygon set on the left + The polygon set on the right + Current triangle
It looks like an energy Necklace , By enumerating three points , Then calculate the set , Because we need to calculate the set of all individual triangles first then And then recurs to the weight of a whole polygon ( Enumerate two endpoints , At least one point in the middle , therefore len by 3, To ensure at least one point in the middle )
therefore len At most from 3 Start enumeration , Because of n vertices , at most n Edge shape , So enumerate to n,3<=len<=n
We found that , Because different triangles cannot intersect , So for a polygon set

State means : All by (i,i+1),(i+1,i+2)...(j-1,j) A collection of triangles divided by polygons
subset division / State calculation : At present dp[i][j] It can be divided into three subsets = Polygon set on the left + Current triangle + Set of polygons on the right ,dp[i][j]=dp[i][k]+dp[k][j]+w[i]*w[i]*w[k], According to the break point k Can be divided into multiple subsets
- choice i+1 As a breakpoint
- ...
- choice j-1 As a breakpoint
Recursive order :3<=len<=n
initialization : infinity
The border :dp[i][i]=dp[i][i+1]=0
Due to the need for high accuracy , So here we use vector Use high precision
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N = 55;
vector<int> dp[N][N];
int w[N];
typedef long long ll;
vector<int> init(ll a)
{
if (a == (long long)1e18)
{
vector<int> res(35, 0);
res.push_back(1);
reverse(res.begin(), res.end());
return res;
}
vector<int> res;
while (a)
{
res.push_back(a % 10);
a /= 10;
}
reverse(res.begin(), res.end());
return res;
}
vector<int> add(vector<int> a, vector<int> b)
{
vector<int> c;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int t = 0;
for (int i = 0;i < a.size() || i < b.size();i++)
{
if (i < a.size())
t += a[i];
if (i < b.size())
t += b[i];
c.push_back(t % 10);
t /= 10;
}
if (t)
c.push_back(t);
reverse(c.begin(), c.end());
return c;
}
vector<int> mul(vector<int> a, ll r)
{
vector<int> c;
reverse(a.begin(), a.end());
ll t = 0;
for (int i = 0;i < a.size() || t;i++)
{
if (i < a.size())
t += a[i] * r;
c.push_back(t % 10);
t /= 10;
}
while (c.back() == 0 && c.size() > 1) c.pop_back();
reverse(c.begin(), c.end());
return c;
}
bool cmp(vector<int>& a, vector<int>& b)
{
if (a.size() != b.size())
return a.size() < b.size();
else
for (int i = 0;i < a.size();i++)
if (a[i] != b[i])
return a[i] < b[i];
return false;
}
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> w[i];
for (int i = 1;i <= n;i++)
for (int j = 1;j <= n;j++)
dp[i][j] = init((long long)1e18);
for (int len = 1;len <= n;len++)
for (int i = 1;i + len - 1 <= n;i++)
{
int j = i + len - 1;
if (len == 1 || len == 2) dp[i][j] = init(0);
else
for (int k = i + 1;k < j;k++)
{
auto temp = add(dp[i][k], dp[k][j]);
auto t = mul(mul(init(w[i]), w[j]), w[k]);
temp = add(temp, t);
if (cmp(temp,dp[i][j]))
dp[i][j] = temp;
}
}
for (auto t : dp[1][n])
cout << t;
return 0;
}边栏推荐
- 10 minutes to get started quickly composition API (setup syntax sugar writing method)
- 现货黄金分析的技巧有什么呢?
- Liteos learning - first knowledge of development environment
- 【LeetCode 43】236. The nearest common ancestor of binary tree
- Six lessons to be learned for the successful implementation of edge coding
- 跨域?同源?一次搞懂什么是跨域
- 游戏思考15:全区全服和分区分服的思考
- 6-3漏洞利用-SSH环境搭建
- ES6 new method of string
- ECS project deployment
猜你喜欢

Finally got byte offer, 25-year-old inexperienced experience in software testing, to share with you

浅浅了解Servlet

Three core problems of concurrent programming

人工智能在网络安全中的作用

What is AQS and its principle

Four basic strategies for migrating cloud computing workloads
![[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production](/img/b7/aecb815ca9545981563a1e16cfa19e.jpg)
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
![[IVX junior engineer training course 10 papers to get certificates] 09 chat room production](/img/a8/25215e74162b7ab3f29df65681932b.jpg)
[IVX junior engineer training course 10 papers to get certificates] 09 chat room production

How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?

Edge computing accelerates live video scenes: clearer, smoother, and more real-time
随机推荐
D discard the virtual recovery method
Architecture evolution from MVC to DDD
How can the tsingsee Qingxi platform play multiple videos at the same time on the same node?
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
6-2漏洞利用-ftp不可避免的问题
电子协会 C语言 1级 32、计算2的幂
matlab 使用 resample 完成重采样
The technology boss is ready, and the topic of position C is up to you
企业应该选择无服务器计算吗?
Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
遷移雲計算工作負載的四個基本策略
[image enhancement] vascular image enhancement based on frangi filter with matlab code
Learning notes 25 - multi sensor front fusion technology
Docker installing Oracle_ 11g
How can I batch produce the same title for the video?
[IVX junior engineer training course 10 papers] 06 database and services
Laravel artisan common commands
Luogu p1775 stone merger (weakened version)
【视频】马尔可夫链蒙特卡罗方法MCMC原理与R语言实现|数据分享
Just using the way and method of consuming the Internet to land and practice the industrial Internet will not bring long-term development