의 특정 합계와 같을 수있는 모든 순열/조합 찾기이 간단한 문제를 해결하도록 요청 받았고 프로그래밍 기술이 매우 비참합니다. 여기,matlab
다음 항목이 주어지면 총 비용이 정확히 $ 100이되도록 모든 의류 품목 조합을 찾으십시오.
여기 내 코드 :이 코드는 원시 알고
tshirt=20; %price of tshirt
shorts=15; %price of shorts
socks=5; %price of socks
solution=0;
for i=20 %cannot have more than 20 socks (over $100)
for j = 6 %cannot have more than 6 shorts (over $100)%cannot have more than 20 socks (over $100)
for k=5 %cannot have more 5 tshirts (over $100)
%Some code or function that will add them up so they are
%exactly $100??
tshirt+shorts+socks==100
end
end
end
,하지만 난에 접근하는 방법에 대한 우둔입니다 .... 어떤 도움이 많이 이해할 수있을 것이다.
이것은 기본적으로 동전 변경 문제이므로이를 검색하는 것이 좋습니다. –
마지막 공식은 i * tshirt + j * shorts + k * socks == 100처럼 보입니다. 나는 Matlab을 기억하지 않지만 일반적으로 다음을 가져야한다. if (i * tshirt + j * shorts + k * socks == 100) solution = solution + 1 –