• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            為生存而奔跑

               :: 首頁 :: 聯系 :: 聚合  :: 管理
              271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

            留言簿(5)

            我參與的團隊

            搜索

            •  

            積分與排名

            • 積分 - 328615
            • 排名 - 74

            最新評論

            閱讀排行榜

            評論排行榜

             

            對于每一次的操作用矩陣表示,這里的矩陣a是(n+1,n+1),初始化為一個單位矩陣

            ‘g’ num 操作,表示使第num個數增加1,使矩陣a的第num行最后一個元素增加1,即a[num][last]+=1

            ‘e’ num 操作,表示使第num個數變為0,使矩陣a的第num行全部變為0

            即for(i=1:i<=last;i++) a[num][i]=0;

            ‘s’ num1,num2操作,表示使第num1和num2元素交換位置,使矩陣a 的第num1和num2行互換就可以了for(i=1:i<=last;i++) swap(a[num1][i],a[num2][i]);

            最后結果就是a[i][n+1]

            #include<iostream>
            #include
            <algorithm>
            #include
            <string>
            #include
            <vector>
            #include
            <cmath>
            #include
            <map>
            using namespace std;
            #define maxn 102
            int m,n;
            void mul(__int64 sor1[][maxn],__int64 sor2[][maxn],__int64 des[][maxn])
            {
                
            for(int i=0;i<=n;i++)
                    
            for(int j=0;j<=n;j++)
                    
            {
                        des[i][j]
            =0;
                        
            for(int k=0;k<=n;k++)
                            
            if(sor1[i][k] && sor2[k][j])
                                des[i][j]
            +=sor1[i][k]*sor2[k][j];
                    }

            }

            void copy(__int64 sor[][maxn],__int64 des[][maxn])
            {
                
            for(int i=0;i<=n;i++)
                    
            for(int j=0;j<=n;j++)
                        des[i][j]
            =sor[i][j];
            }

            void multiply(__int64 sor[][maxn],__int64 des[][maxn],int n)
            {
                
            if(n<=0)
                
            {
                    
            for(int i=0;i<=n;i++)
                    
            {
                        
            for(int j=0;j<=n;j++)
                            des[i][j]
            =0;
                        des[i][i]
            =1;
                    }

                }

                
            else if(n==1)
                    copy(sor,des);
                
            /*else if(n==2)
                    mul(sor,sor,des);
            */

                
            else
                
            {
                    __int64 tmp[maxn][maxn];
                    multiply(sor,tmp,n
            /2);
                    mul(tmp,tmp,des);
                    
            if(n%2)
                    
            {
                        copy(des,tmp);
                        mul(tmp,sor,des);
                    }

                }

            }

            void swap(__int64 & a1,__int64 & a2)
            {
                __int64 tmp;
                tmp
            =a1;    a1=a2;    a2=tmp;
            }

            void print(__int64 a[][maxn])
            {
                
            for(int i=0;i<=n;i++)
                
            {
                    
            for(int j=0;j<=n;j++)
                        printf(
            "%d ",a[i][j]);
                    printf(
            "\n");

                }

            }

            int main()
            {
                
            char cmd;
                
            int k;
                __int64 mat[maxn][maxn],ans[maxn][maxn];
                
            while(scanf("%d%d%d",&n,&m,&k)!=EOF,n||m||k)
                
            {
                    memset(mat,
            0,sizeof(mat));
                    
            for(int i=0;i<=n;i++)
                        mat[i][i]
            =1;
                    
            while(k--)
                    
            {
                        getchar();
                        cmd
            =getchar();
                        
            if(cmd=='s')
                        
            {
                            
            int id1,id2;
                            scanf(
            "%d%d",&id1,&id2);
                            id1
            --,id2--;
                            
            for(int i=0;i<=n;i++)
                                swap(mat[id1][i],mat[id2][i]);
                        }

                        
            else if(cmd=='g')
                        
            {
                            
            int id;
                            scanf(
            "%d",&id);
                            id
            --;
                            mat[id][n]
            ++;
                        }

                        
            else
                        
            {
                            
            int id;
                            scanf(
            "%d",&id);
                            id
            --;
                            
            for(int i=0;i<=n;i++)
                                mat[id][i]
            =0;
                        }

                    }

                    
            //print(mat);
                    multiply(mat,ans,m);
                    printf(
            "%I64d",ans[0][n]);
                    
            for(int i=1;i<n;i++)
                        printf(
            " %I64d",ans[i][n]);
                    printf(
            "\n");
                }

            }
            posted on 2009-08-17 14:36 baby-fly 閱讀(524) 評論(1)  編輯 收藏 引用 所屬分類: Algorithm

            Feedback

            # re: 【矩陣問題】PKU 3735 Training little cats 2010-11-06 12:22 aaa
            你是做系統的?看你的編程風格  回復  更多評論
              

            理论片午午伦夜理片久久| 无码AV波多野结衣久久| yellow中文字幕久久网| 精品无码久久久久久国产| 久久久久久久精品妇女99| 久久国产精品一国产精品金尊| 久久亚洲国产精品一区二区| 色偷偷88欧美精品久久久| 大伊人青草狠狠久久| segui久久国产精品| 日韩久久久久久中文人妻| 99热精品久久只有精品| 18岁日韩内射颜射午夜久久成人| 久久精品视频网| 亚洲AV成人无码久久精品老人| 精品免费久久久久国产一区| 久久久久无码精品国产| 精品国产日韩久久亚洲| 麻豆精品久久精品色综合| 无码国产69精品久久久久网站 | 久久精品国产色蜜蜜麻豆| 国产婷婷成人久久Av免费高清| 亚洲国产婷婷香蕉久久久久久| 94久久国产乱子伦精品免费| 欧洲人妻丰满av无码久久不卡| 久久久久亚洲国产| 久久久久亚洲精品男人的天堂| 亚洲狠狠久久综合一区77777| 久久精品天天中文字幕人妻 | 久久国内免费视频| 久久精品国产国产精品四凭| 久久久久综合网久久| 国产精品久久久久久久久| 久久久久99精品成人片欧美| 久久久久AV综合网成人| 日韩AV无码久久一区二区| 久久亚洲私人国产精品| 精品人妻久久久久久888| 99精品久久精品一区二区| av无码久久久久不卡免费网站| 欧美熟妇另类久久久久久不卡 |