“玲珑杯”ACM比赛 Round #18---图论你先敲完模板(DP+思维)
DESCRIPTION
INPUT
OUTPUT
SAMPLE INPUT
2
3 2
3 5 7
3 10
3 5 7
SAMPLE OUTPUT
12
26
HINT
官方题解:
代码如下:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; typedef long long LL; long long dp[100005]; int a[100005]; int main() { ///cout << "Hello world!" << endl; int T; cin>>T; while(T--) { int n; long long x; scanf("%d%lld",&n,&x); for(int i=1;i<=n;i++) scanf("%d",&a[i]); dp[0]=0; dp[1]=0; for(int i=2;i<=n;i++) { dp[i]=1e18+3; int j=i-60; if(j<1) j=1; for(;j<=i;j++) { int s=a[i]-a[j]; if(s<60){ long long t=dp[j]+(1LL<<s)+x; dp[i]=min(dp[i],t); } //cout<<"t-----"<<i<<"-----"<<j<<"-----"<<t<<endl; } } printf("%lld\n",dp[n]); } return 0; }