1976: 搬运工小明
#include
#include
#include
#include
using namespace std;
long long a[100010];
int main()
{
int T;
cin>>T;
while(T--)
{
int N,M;
cin>>N>>M;
memset(a,0,sizeof(a));
long long maxm=0;
for(int i=1;i<=M;i++)
{
cin>>a[i];
maxm=a[i]>maxm?a[i]:maxm;
}
if(N>=M)
{
cout<endl;
continue;
}
while(maxm)
{
int cnt=0;
long long sum=0;
for(int i=1;i<=M;i++)
{
sum=sum+a[i];
if(sumif(i==M)
{
cnt++;
sum=0;
}
continue;
}
else if(sum==maxm)
{
cnt++;
sum=0;
}
else if(sum>maxm)
{
cnt++;
i--;
sum=0;
}
}
if(cnt<=N)
{
cout<endl;
break;
}
else
maxm++;
}
}
return 0;
}
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int MAXN=2e5+10;
int a[MAXN];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(a,0,sizeof(a));
int n;
scanf("%d",&n);
for(int i=0;iscanf("%d",&a[i]);
}
//cout<
//cout<
int t=1;
int m=0;
while(t2 ;
m++;
}
//cout<
//cout<<(1<
bool flag=true;
for(int i=0;i<(1<//cout<<"-----"<
int tmp=i;
int sum=0;
for(int j=1;j<=m;j++)
{
sum=sum<<1;
//cout<<"tmp&1:"<<(tmp&1)<
sum=sum|(tmp&1);
tmp=tmp>>1;
//cout<<"sum: "<
}
if(!flag) printf(" ");
else flag=false;
printf("%d",a[sum]);
//cout<
}
printf("\n");
}
return 0;
}
#include
#include
#include
#include
using namespace std;
int N,M;
double nmap[505][505];
void init()
{
for(int i=1;i3;i++)
for(int j=1;j3;j++)
nmap[i][j]=10000;
}
int main()
{
int u,v;
double w;
while(cin>>N>>M)
{
init();
bool suc=false;
for(int i=0;icin>>u>>v>>w;
nmap[u][v]=min(nmap[u][v],w); //都是有向边
}
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
{
if(nmap[j][k]>nmap[j][i]*nmap[i][k])
nmap[j][k]=nmap[j][i]*nmap[i][k];
}
for(int i=1;i<=N;i++) //检查有没有环满足条件
if(nmap[i][i]<1)
{
suc=true;
break;
}
if(suc)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
#include
#include
#include
#include
typedef long long ll;
using namespace std;
const int maxn = 10;
int T, n;
ll myints[] = {0,1,2,3,4,5,6,7}, sample[maxn][maxn];
ll checkSgn(){ // 计算逆序数。
int cnt = 0;
for(int i = 0; i < n-1; i++)
for(int j = i+1; j < n; j++)
if(myints[j] < myints[i])
cnt++;
if(cnt & 1)
return -1;
return 1;
}
int main(){
#ifdef TEST
freopen("test.txt", "r", stdin);
#endif // TEST
cin >> T;
while(T--){
cin >> n;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> sample[i][j];
ll res = 0;
do{
ll temp = 1;
for(int i = 0; i < n; i++){
temp *= sample[i][myints[i]];
if(i >= 2)
if(sample[i][myints[i]] == 82 && sample[i-1][myints[i-1]] == 83 && sample[i-2][myints[i-2]] == 83){
temp /= (82*83*83);
}
}
temp *= checkSgn(); // 将一次排列得出的结果乘上1或-1.
res += temp;
}while(next_permutation(myints, myints+n));
cout << res << endl;
}
return 0;
}
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int maxn=200+5;
const LL INF=1ll<<50;
LL sum[maxn],dp[maxn][maxn],a[maxn],c[maxn];
int n,b[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lld",a+i);
for(int i=1;i<=n;++i)scanf("%d",b+i);
for(int i=1;i<=n;++i)c[i]=a[b[i]];
for(int i=1;i<=n;++i)sum[i]=sum[i-1]+c[i];
for(int i=1;i<=n;++i)
for(int j=i+1;j<=n;++j)
dp[i][j]=INF;
for(int i=1;i<=n;++i)dp[i][i]=c[i];
for(int j=2;j<=n;++j)
{
for(int i=j-1;i>0;--i)
{
dp[i][j]=min(dp[i][j-1],dp[i+1][j])+sum[j]-sum[i-1];
for(int k=i+1;k<=j-1;++k)
{
dp[i][j]=min(dp[i][j],dp[i][k-1]+sum[j]-sum[i-1]+dp[k+1][j]);
}
}
}
printf("%lld\n",dp[1][n]);
}
return 0;
}