C语言 求子集重量之和
来源:互联网 发布:诺思星被淘宝大学开除 编辑:程序博客网 时间:2024/05/22 06:10
求子集重量之和(Calculate the sum of a subset's weight)
时限:100ms 内存限制:10000K 总时限:1000ms
描述:
现有n件物品,已知它们的重量,求其中一个子集的重量之和。
There are n things, we are known their weight, calculate the sum of a subset's weight.
输入:
先输入一个整数n,再输入n件物品的重量,最后输入n个元素表示子集(第i个元素为0,表示子集中不包含该物品,第i个元素为1,表示子集中包含该物品)。
Input a positive integer n first, and then Input the weight of n items, at last we input the n numbers indicate the subset (i-th element is 0, which means that the subset does not contain the i-th item, the i-th element is 1, which means that the subset contains the i-th item).
输出:
输出该子集的重量之和。
Output the sum of subset's weight.
输入样例:
52 9 8 7 50 1 1 0 1
输出样例:
22
#include<stdio.h>int main(){int n,a[2][100],i,j,sum=0;scanf("%d",&n);for(i=0;i<2;i++){for(j=0;j<n;j++){scanf("%d",&a[i][j]);}}for(j=0;j<n;j++){if(a[1][j]==1)sum=sum+a[0][j];}printf("%d",sum);return 0;}
- C语言 求子集重量之和
- 求子集重量之和(链表)
- NOJ1322求子集重量之和(Calculate the sum of a subset's weight)
- C语言递归求子集
- 【c语言】求两个整数之和
- C语言:求两个整数之和
- C语言 求两个整数之和
- 【C语言】求阶乘与阶乘之和
- 【C语言】求一个整数的因子之和
- 【C语言】 递归求非负数的每一位之和
- C语言实验——求两个整数之和
- oj1975: C语言实验——求两个整数之和
- C语言求二维数组a所有偶数元素之和
- C语言实验——求两个整数之和
- C语言实验——求两个整数之和
- C语言实验——求两个整数之和
- c语言中,求1到n的阶乘之和
- c语言:求一个3*3矩阵对角线元素之和
- AJP13服务利用
- linux中的自动安装虚拟机脚本
- Spark Streaming与Storm的对比分析
- HDU 4403 A very hard Aoshu problem DFS
- 害人和利己
- C语言 求子集重量之和
- 对象深拷贝
- MySQL数据库(python)
- 周报二
- C和C++区别(1、有默认值的函数)
- 简单hash学习
- 2017-10-24 2周2次课
- MarkdownPad专业版(破解)
- 从YOLOv1谈到YOLOv2(5)二代速度与功能的改进