µÇ¼ | Ê×Ò³ -> »ªÐÂÏÊÊ -> Çóѧʨ³Ç | Çл»µ½£º´«Í³°æ / sForum | Ê÷ÐÎÁбí
CS1102 Lab2a, Qn3, Qn4£­´ðÖØÉú
<<ʼҳ¡¡ [1]¡¡ Ä©Ò³>>¡¡

CS1102 Lab2a, Qn3, Qn4£­´ðÖØÉúPaint Disk ÄǵÀÌâ·Ç³£¼òµ¥¡£
¸ø m ÖÖcolor, N¸ösectors£¬ÓжàÉÙÖÖpaintµÄ·½·¨

paint µÚÒ»¸ösectorÓÐ m ÖÖ¿ÉÄÜÐÔ£¬paint µÚ¶þ¸ösectorÓÐ m-1 ÖÖ¿ÉÄÜÐÔ£¬Ò»Ö±µ½ µÚ n ¸ösector. Õâʱ»áÓÐÖظ´µÄ¿ÉÄÜ£¬¼´µÚÒ»¸öºÍ×îºóÒ»¸ösectorÊÇͬһÖÖÑÕÉ«£¬°ÑÕâЩÇé¿ö¼õÈ¥¼´¿É¡£

µÚÒ»¸öºÍ×îºóÒ»¸ösectorÖظ´µÄÇé¿öÓжàÉÙÖÖÄØ£¿Èç¹û°ÑµÚÒ»¸ösectorºÍ×îºóÒ»¸ösector¿´³ÉÊÇÒ»¸ösector£¬ÄÇôÿÖÖÖظ´µÄÇé¿ö£¬Ç¡ºÃÊÇ m ÖÖcolor, N-1 ¸ö sectorµÄÇé¿ö¡£ËùÒÔrecursion ¾ÍÊÇ

PD(m, n) = m*(m-1)^(n-1) - PD(m, n-1)

»ù±¾Çé¿öÓÐÈô¸ÉÖÖ£¬Çë×Ô¼ºÈ¥·ÖÎöºÃÁË£¬²»ÔÙ¶à˵¡£

×îºóÒ»µÀÌâÄ¿·Ç³£ÄÑ£¬ÌâÄ¿µÄÒâ˼ÊÇ£¬24=2*12=3*8=4*6=2*2*6=...
{2, 12}ÊÇ24µÄÒ»¸öset£¬{3,8}Ò²ÊÇ24µÄÒ»¸öset£¬{2,12}ºÍ{12, 2}Ëãͬһ¸öset£¬{24}Ò²ÊÇ{24}µÄÒ»¸öset¡£24ÓÐ7¸öÕâÑùµÄset¡£ÒªÄãËã³öÈô¸ÉÊýµÄsetµÄ¸öÊý£¬²¢ÇÒ°Ñ×î´óµÄÄǸöÊýÒÔ¼°ËüµÄsetÊýÕÒ³öÀ´¡£
ÕâµÀÌâºÜÄÑ¡£±ØÐëÓÃDynamic Programming²ÅÄÜ×ö³öÀ´²¢ÇÒ²»³¬Ê±¡£ÎÒÓÃrecursion×ö³öÀ´£¬3¸öaccept£¬7¸ö³¬Ê±¡£ÏëÏë¸øµÄÊý¿ÉÄÜÊÇ1000,000£¬Èç¹ûrecursion×ö£¬ËüµÄÓÃʱ¸Ã¶àÉÙ°¡£¿
¾ÍËãÓÃDynamic Programming Ò²ºÜÄÑÏë³öalgorithm¡£Çë²Î¿¼ÒÔÏÂÒ»¶Îcode

int results[] = new int [max+1];
results[1] = 1;
for (int i=2; i<=max; i++) {
for (int j=1; j<=max/i; j++) {
results[i*j] += results[j];
}
//½¨ÒéÕâÀï¼ÓÒ»¶Îcode°Ñresults print³öÀ´¿´¿´±È½ÏÖ±¹Û
}
[duck (2-12 1:56, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]1Â¥

¹þ¹þ£¬ÎÒForwardÎÒ×éµÄÈËÕâ¸öpostÁË[Climbing (2-12 2:09, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]2Â¥

(ÒýÓà Climbing:¹þ¹þ£¬ÎÒForwardÎÒ×éµÄÈËÕâ¸öpostÁË)Ì«¹ý·ÖÁË°É£¡£¡£¡ÄãÔõô¿ÉÒÔÕâÑù£¿
ÈÃËûÃÇÀ´ÕâÀï¿´ºÃÁË£¬¿É±ðÒÔlabTAµÄÉí·Ý·¢¸øËûÃÇ°¡£¬²»È»±ðµÄ×éµÄÈË»ácomplainµÄ°¡¡£

½¬ºýÉÏÓÖ½«ÏÆÆðÒ»·¬ÐÈ·çѪÓêµÄÕù¶·¡­¡­
[duck (2-12 11:23, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]3Â¥

(ÒýÓà duck:Ì«¹ý·ÖÁË°É£¡£¡£¡ÄãÔõô¿ÉÒÔÕâÑù£¿ ÈÃËûÃÇÀ´ÕâÀï¿´ºÃÁË£¬¿É±ðÒÔlabTAµÄÉí·Ý·¢¸øËûÃÇ°¡£¬²»È»±ðµÄ×éµÄÈË»ácomplainµÄ°¡¡£ ½¬ºýÉÏÓÖ½«ÏÆÆð...)~[ûÂäÊéͯ (2-12 12:37, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]4Â¥

solution to that "difficult question""×îºóÒ»µÀÌâÄ¿·Ç³£ÄÑ£¬ÌâÄ¿µÄÒâ˼ÊÇ£¬24=2*12=3*8=4*6=2*2*6=...
{2, 12}ÊÇ24µÄÒ»¸öset£¬{3,8}Ò²ÊÇ24µÄÒ»¸öset£¬{2,12}ºÍ{12, 2}Ëãͬһ¸öset£¬{24}Ò²ÊÇ{24}µÄÒ»¸öset¡£24ÓÐ7¸öÕâÑùµÄset¡£ÒªÄãËã³öÈô¸ÉÊýµÄsetµÄ¸öÊý£¬²¢ÇÒ°Ñ×î´óµÄÄǸöÊýÒÔ¼°ËüµÄsetÊýÕÒ³öÀ´¡£"

really?

Here is a possible way:

Firstly, use recursion to get the factoriazation of the number, say 24 = 2^3*3
N=p1^e1*p2^e2*p3^e3...*(pn^en)
p1^e1 means p1 tp the power of e1.

Then, use this formula:
number of different set=(e1+1)*(e2+1)*...(en+1)-1, here minus 1 is to remove {1, N} and {N, 1} duplication.

So surprise, a TA says such question is "very difficult". Do you think you are disappointing the students?

Shamed, shamed, shamed......

:D Kidding.
[»¨Â¶Ë® (2-12 14:36, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]5Â¥

(ÒýÓà »¨Â¶Ë®:solution to that "difficult question""×îºóÒ»µÀÌâÄ¿·Ç³£ÄÑ£¬ÌâÄ¿µÄÒâ˼ÊÇ£¬24=2*12=3*8=4*6=2*2*6=... {2, 12}ÊÇ24µÄÒ»¸öset£¬{3,8}Ò²Ê...)btwI use only 30 sec to think about this question. If anything wrong, i won't take any responsibility. Haha![»¨Â¶Ë® (2-12 14:38, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]6Â¥

(ÒýÓà »¨Â¶Ë®:solution to that "difficult question""×îºóÒ»µÀÌâÄ¿·Ç³£ÄÑ£¬ÌâÄ¿µÄÒâ˼ÊÇ£¬24=2*12=3*8=4*6=2*2*6=... {2, 12}ÊÇ24µÄÒ»¸öset£¬{3,8}Ò²Ê...)aiyait seems i misunderstood the question, the formula is corrent if only 2 elements in a set is required.[»¨Â¶Ë® (2-12 14:42, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]7Â¥

(ÒýÓà duck:Ì«¹ý·ÖÁË°É£¡£¡£¡ÄãÔõô¿ÉÒÔÕâÑù£¿ ÈÃËûÃÇÀ´ÕâÀï¿´ºÃÁË£¬¿É±ðÒÔlabTAµÄÉí·Ý·¢¸øËûÃÇ°¡£¬²»È»±ðµÄ×éµÄÈË»ácomplainµÄ°¡¡£ ½¬ºýÉÏÓÖ½«ÏÆÆð...)żÊÇforwardÕâ¸öLINKѽ£¬Ä㣬²»Òª¼¤¶¯Âï[Climbing (2-12 17:03, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]8Â¥

(ÒýÓà »¨Â¶Ë®:solution to that "difficult question""×îºóÒ»µÀÌâÄ¿·Ç³£ÄÑ£¬ÌâÄ¿µÄÒâ˼ÊÇ£¬24=2*12=3*8=4*6=2*2*6=... {2, 12}ÊÇ24µÄÒ»¸öset£¬{3,8}Ò²Ê...)this way, most possibly, will get time out" error.[Climbing (2-12 17:05, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]9Â¥

(ÒýÓà duck:Ì«¹ý·ÖÁË°É£¡£¡£¡ÄãÔõô¿ÉÒÔÕâÑù£¿ ÈÃËûÃÇÀ´ÕâÀï¿´ºÃÁË£¬¿É±ðÒÔlabTAµÄÉí·Ý·¢¸øËûÃÇ°¡£¬²»È»±ðµÄ×éµÄÈË»ácomplainµÄ°¡¡£ ½¬ºýÉÏÓÖ½«ÏÆÆð...)Õù¶·µÄºóÃæ
ÊÇÒ»ÍÅÂÒÆß°ËÔãµÄ½¬ºý¡£¡£¡£¡£
[mean (2-12 18:25, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]10Â¥

(ÒýÓà »¨Â¶Ë®:aiyait seems i misunderstood the question, the formula is corrent if only 2 elements in a set is required.)If so, you are not able to get itEven if to compute all set with only two elements, your algorithm is not able to get it.
24 = 2^3*3, by your formula, the number of sets are 4*2-1 = 7. In fact, it is {24}, {2, 12}, {3, 8}, {4, 6}, which is only 4.
:)

I am not going to pointing your mistake here. Anyway, read the question carefully.

I do not think this question is able to be solved by permutation and combination formula. Indeed, it is hard to solve it. In programming, we also consider complexity of an algorithm. Another bottleneck to this problem is that there may be about 1000,000 number to compute. Then how?
Think about it...
[duck (2-12 20:08, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]11Â¥

(ÒýÓà duck:If so, you are not able to get itEven if to compute all set with only two elements, your algorithm is not able to get it. 24 = 2...)qie~~Don't teach me like you are my TA. You are a TA, so am I. ûʲôÁ˲»Æð£¬Êܲ»ÁËÄã˵»°µÄ̬¶È£¬ÎÒÉÁÁË¡£

[»¨Â¶Ë® (2-12 20:17, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]12Â¥

ÍÛ£¬µ±TAºÃÁ˲»Æðѽ£¡duck and climbing ¶¼ÊÇ°É£¿ºÃÀ÷º¦Ñ½£¿

ÄãÃÇÊDz»ÊǶ¼ÄõÄA+²Å¿ÉÒÔµ±µÄ£¿CAPÓÐûÓÐÒªÇó£¿Á½Î»¸ßÈËÏë±Ø¶¼Êǹý4.9µÄ°É£¿³ç°Ýing~~
[ÎÒÏëÎÒÊǺ£ (2-12 20:21, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]13Â¥

ÎÒÕâ¸öÌû×ÓÉêÇëÖö¥Ò»ÖÜ£¬µ½ÏÂÖܶþ·ÅÏÂÈ¥[duck (2-12 21:58, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]14Â¥

Ì«ÉñÆæÁË£¡¶àлÁË¡£²»È»»¹²»ÖªµÀÒªÏë¶à¾Ã[ÎÒµÄÅ£±Æ (2-13 20:15, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]15Â¥

ÓÐûÓкõķ½·¨½â¾ötimeÎÊÌ⣿ÎÒµÄcodeËäȻͨ¹ýÁËonline jugdge,µ«ÎÒÊÇÖ±½ÓÕë¶Ôonline judgeÀ´Éè¼ÆµÄ¡£µ«ÊDz»¹»efficient. ÇëÀÏÐÖÌáʾһÏ¡£¶àл£¡^_^[Ô­Öø (2-14 22:59, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]16Â¥

(ÒýÓà ԭÖø:ÓÐûÓкõķ½·¨½â¾ötimeÎÊÌ⣿ÎÒµÄcodeËäȻͨ¹ýÁËonline jugdge,µ«ÎÒÊÇÖ±½ÓÕë¶Ôonline judgeÀ´Éè¼ÆµÄ¡£µ«ÊDz»¹»efficient. ÇëÀÏÐÖÌáʾһÏ...)³ÙЩʱºò°ÉµÈÕâ¸ölab½áÊøÒÔºó¡£ÎÒ¿ÉÒÔ¿¼ÂÇ°ÑÎÒµÄprogramÌù³öÀ´¡£:D
[duck (2-14 23:45, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]17Â¥

(ÒýÓà duck:³ÙЩʱºò°ÉµÈÕâ¸ölab½áÊøÒÔºó¡£ÎÒ¿ÉÒÔ¿¼ÂÇ°ÑÎÒµÄprogramÌù³öÀ´¡£:D )ºÃ£¬Ð»Ð»£¡^_^[Ô­Öø (2-15 0:17, Long long ago)] [ ´«Í³°æ | sForum ][µÇ¼ºó»Ø¸´]18Â¥


<<ʼҳ¡¡ [1]¡¡ Ä©Ò³>>¡¡
µÇ¼ | Ê×Ò³ -> »ªÐÂÏÊÊ -> Çóѧʨ³Ç | [ˢб¾Ò³] | Çл»µ½£º´«Í³°æ / sForum