# 中石油训练混合训练第七场

## 狼

3
3 5 7
8 2 0


17


for(int i=1;i<=n;i++)
dp[i][i]=a[i]+b[i-1]+b[i+1];///左右两边都加上


ll temp=dp[i][k-1]+a[k]+b[i-1]+b[j+1]+dp[k+1][j];
dp[i][j]=min(dp[i][j],temp);


#include <bits/stdc++.h>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
const ll inf = 1e15;
const ll INF = 0x3f3f3f3f;
const int maxn = 2e6 + 7;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b)
{
ll t;
while(b!=0)
{
t=a%b;
a=b;
b=t;
}
return a;
}
ll qPow(ll x, ll k)
{
ll res = 1;
while(k) {
if(k&1)
res=(res*x);
k>>=1;
x=(x*x);
}
return res;
}
ll maxx=-1;
ll minn=inf;
ll num2[maxn];
ll num[maxn];
ll res,ans;
int sum=0;
map<string,ll> mp;
vector<ll> vet;
priority_queue <int ,vector<int> ,greater<int> > xiaogen;
queue <ll> duilie;
priority_queue <int ,vector<int> ,less<int> > que;
ll a[500],b[500];
ll dp[500][500];
int main()
{
memset(dp,0x3f3f3f3f,sizeof dp);
for(int i=1;i<=n;i++) dp[i][i]=a[i]+b[i-1]+b[i+1];///左右两边都加上
for(int i=n-1;i>=1;i--){
for(int j=i+1;j<=n;j++){
ll temp1=dp[i+1][j]+a[i]+b[i-1]+b[j+1];
ll temp2=dp[i][j-1]+a[j]+b[i-1]+b[j+1];
dp[i][j]=min(temp1,temp2);
for(int k=i+1;k<j;k++)
{
ll temp=dp[i][k-1]+a[k]+b[i-1]+b[j+1]+dp[k+1][j];
dp[i][j]=min(dp[i][j],temp);
}
}
}
cout<<dp[1][n]<<endl;
return 0;
}
/**
3
3 5 7
8 2 0

17

**/

/**************************************************************
Problem: 15408
Language: C++
Result: 正确
Time:108 ms
Memory:35252 kb
****************************************************************/


## 好朋友

1
2 10
2 3


7


【数据范围】

#include <bits/stdc++.h>
using namespace std;
#define wuyt main
typedef long long ll;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
const ll inf = 1e15;
const ll INF = 0x3f3f3f3f;
const int maxn = 2e6 + 7;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b)
{
ll t;
while(b!=0)
{
t=a%b;
a=b;
b=t;
}
return a;
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
void DFS(int now,int op,ll fenmu){
if(now!=1) ans+=m/fenmu*(op);
for(int i=now;i<=n;i++) DFS(i+1,-op,lcm(fenmu,num[i]));
}
int main()
{
while(cnt--){
ans=0;
/// 第一次之后*-1，所以开始要是-1而不是1
DFS(1,-1,1);
cout<<ans<<endl;
}
return 0;
}
/**
1
2 10
2 3
**/



03-04 108

04-23 555

05-02 177

03-17 6104

05-08 28

07-06 1万+

02-23 4万+

02-19 534

09-09 104

#### 国学堂-梁冬对话吴伯凡

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。