标签:log using return sys describe ring use std main
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int n;
int m[10]={0};//每个砝码的质量
int x[10]={0};//每个砝码的数量
vector<int>weight;
while(cin>>n)
{
for(int i=0;i<n;i++)
cin>>m[i];
for(int j=0;j<n;j++)
cin>>x[j];
weight.push_back(0);
for(int i=1;i<=x[0];++i)
weight.push_back(i*m[0]);
for (int i=1;i<n;i++)
{
int len=weight.size();
for(int j=1;j<=x[i];++j)
{
for(int z=0;z<len;++z)
{
int wei=weight[z]+j*m[i];
if(find(weight.begin(),weight.end(),wei)==weight.end())
weight.push_back(weight[z]+j*m[i]);
}
}
}
cout<<weight.size()<<endl;
}
system("pause");
return 0;
}
现有一组砝码,重量互不相等,分别为m1,m2,m3…mn;
每种砝码对应的数量为x1,x2,x3...xn。现在要用这些砝码去称物体的重量,问能称出多少中不同的重量。
标签:log using return sys describe ring use std main
原文地址:http://www.cnblogs.com/zhaodun/p/6925730.html