当前位置:
首页 >
洛谷 P2347 砝码称重
发布时间:2024/4/14
60
豆豆
生活随笔
收集整理的这篇文章主要介绍了
洛谷 P2347 砝码称重
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
P2347 砝码称重
题目描述
设有1g、2g、3g、5g、10g、20g的砝码各若干枚(其总重<=1000),
输入输出格式
输入格式:
输入方式:a1 a2 a3 a4 a5 a6
(表示1g砝码有a1个,2g砝码有a2个,…,20g砝码有a6个)
输出格式:
输出方式:Total=N
(N表示用这些砝码能称出的不同重量的个数,但不包括一个砝码也不用的情况)
输入输出样例
输入样例#1: 复制 1 1 0 0 0 0 输出样例#1: 复制 Total=3思路:搜索
#include<map> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; map<int,int>ma; int b[7]={0,1,2,3,5,10,20}; int a[7],ans,pos[7]; void dfs(int tot,int num){if(tot-1==6){if(!ma[num]) ans++,ma[num]=1;return ;}for(int i=0;i<=a[tot];i++)dfs(tot+1,num+i*b[tot]); } int main(){for(int i=1;i<=6;i++) scanf("%d",&a[i]);ma[0]=1;dfs(1,0);cout<<"Total="<<ans; }
转载于:https://www.cnblogs.com/cangT-Tlan/p/7853751.html
总结
以上是生活随笔为你收集整理的洛谷 P2347 砝码称重的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 谈谈我的移动端rem适配方案
- 下一篇: 硕士研究僧长成记